get_option

Definition:
function get_option( $option, $default = false ) {}

Retrieve option value based on name of option.
If the option does not exist or does not have a value, then the return value will be false. This is useful to check whether you need to install an option and is commonly used during installation of plugin options and to test whether upgrading is required.

Parameters

  • string $option: Name of option to retrieve. Expected to not be SQL-escaped.
  • mixed $default: Optional. Default value to return if the option does not exist.

Return values

returns:Value set for the option.

Defined filters

  • pre_option_$option
    apply_filters( 'pre_option_' . $option, false )
  • option_$option
    apply_filters( 'option_' . $option, maybe_unserialize( $value )

Source code

function get_option( $option, $default = false ) {

	global $wpdb;



	// Allow plugins to short-circuit options.

	$pre = apply_filters( 'pre_option_' . $option, false );

	if ( false !== $pre )

		return $pre;



	$option = trim($option);

	if ( empty($option) )

		return false;



	if ( defined( 'WP_SETUP_CONFIG' ) )

		return false;



	if ( ! defined( 'WP_INSTALLING' ) ) {

		// prevent non-existent options from triggering multiple queries

		$notoptions = wp_cache_get( 'notoptions', 'options' );

		if ( isset( $notoptions[$option] ) )

			return $default;



		$alloptions = wp_load_alloptions();



		if ( isset( $alloptions[$option] ) ) {

			$value = $alloptions[$option];

		} else {

			$value = wp_cache_get( $option, 'options' );



			if ( false === $value ) {

				$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );



				// Has to be get_row instead of get_var because of funkiness with 0, false, null values

				if ( is_object( $row ) ) {

					$value = $row->option_value;

					wp_cache_add( $option, $value, 'options' );

				} else { // option does not exist, so we must cache its non-existence

					$notoptions[$option] = true;

					wp_cache_set( 'notoptions', $notoptions, 'options' );

					return $default;

				}

			}

		}

	} else {

		$suppress = $wpdb->suppress_errors();

		$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );

		$wpdb->suppress_errors( $suppress );

		if ( is_object( $row ) )

			$value = $row->option_value;

		else

			return $default;

	}



	// If home is not set use siteurl.

	if ( 'home' == $option && '' == $value )

		return get_option( 'siteurl' );



	if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )

		$value = untrailingslashit( $value );



	return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );

}

1514

get_object_term_cache

Definition:
function &get_object_term_cache($id, $taxonomy) {}

Retrieves the taxonomy relationship to the term object id.

Parameters

  • int|array $id: Term object ID
  • string $taxonomy: Taxonomy Name

Return values

returns:Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id.

Source code

function &get_object_term_cache($id, $taxonomy) {

	$cache = wp_cache_get($id, "{$taxonomy}_relationships");

1512

get_object_taxonomies

Definition:
function get_object_taxonomies($object, $output = 'names') {}

Return all of the taxonomy names that are of $object_type.
It appears that this function can be used to find all of the names inside of $wp_taxonomies global variable.

Parameters

  • array|string|object $object: Name of the type of taxonomy object, or an object (row from posts)
  • string $output: The type of output to return, either taxonomy ‘names’ or ‘objects’. ‘names’ is the default.

Return values

returns:The names of all taxonomy of $object_type.

Source code

function get_object_taxonomies($object, $output = 'names') {

	global $wp_taxonomies;



	if ( is_object($object) ) {

		if ( $object->post_type == 'attachment' )

			return get_attachment_taxonomies($object);

		$object = $object->post_type;

	}



	$object = (array) $object;



	$taxonomies = array();

	foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) {

		if ( array_intersect($object, (array) $tax_obj->object_type) ) {

			if ( 'names' == $output )

				$taxonomies[] = $tax_name;

			else

				$taxonomies[ $tax_name ] = $tax_obj;

		}

	}



	return $taxonomies;

}

1510

get_objects_in_term

Definition:
function get_objects_in_term( $term_ids, $taxonomies, $args = array() {}

Retrieve object_ids of valid taxonomy and term.
The strings of $taxonomies must exist before this function will continue. On failure of finding a valid taxonomy, it will return an WP_Error class, kind of like Exceptions in PHP 5, except you can’t catch them. Even so, you can still test for the WP_Error class and get the error message.

Parameters

  • int|array $term_ids: Term id or array of term ids of terms that will be used
  • string|array $taxonomies: String of taxonomy name or Array of string values of taxonomy names
  • array|string $args: Change the order of the object_ids, either ASC or DESC

Return values

returns:If the taxonomy does not exist, then WP_Error will be returned. On success the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found.

Source code

function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) {

	global $wpdb;



	if ( ! is_array( $term_ids ) )

		$term_ids = array( $term_ids );



	if ( ! is_array( $taxonomies ) )

		$taxonomies = array( $taxonomies );



	foreach ( (array) $taxonomies as $taxonomy ) {

		if ( ! taxonomy_exists( $taxonomy ) )

			return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) );

	}



	$defaults = array( 'order' => 'ASC' );

	$args = wp_parse_args( $args, $defaults );

	extract( $args, EXTR_SKIP );



	$order = ( 'desc' == strtolower( $order ) ) ? 'DESC' : 'ASC';



	$term_ids = array_map('intval', $term_ids );



	$taxonomies = "'" . implode( "', '", $taxonomies ) . "'";

	$term_ids = "'" . implode( "', '", $term_ids ) . "'";



	$object_ids = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order");



	if ( ! $object_ids )

		return array();



	return $object_ids;

}

1508

get_num_queries

Definition:
function get_num_queries() {}

Retrieve the number of database queries during the WordPress execution.

Return values

returns:Number of database queries

Source code

function get_num_queries() {

	global $wpdb;

	return $wpdb->num_queries;

}

1506