get_posts_by_author_sql

Definition:
function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) {}

Retrieve the post SQL based on capability, author, and type.

Parameters

  • string $post_type: Post type.
  • bool $full: Optional. Returns a full WHERE statement instead of just an ‘andalso’ term.
  • int $post_author: Optional. Query posts having a single author ID.

Return values

returns:SQL WHERE code that can be added to a query.

Defined filters

  • pub_priv_sql_capability
    apply_filters( 'pub_priv_sql_capability', '' )

Source code

function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) {

	global $user_ID, $wpdb;



	// Private posts

	$post_type_obj = get_post_type_object( $post_type );

	if ( ! $post_type_obj )

		return $full ? 'WHERE 1 = 0' : ' 1 = 0 ';



	// This hook is deprecated. Why you'd want to use it, I dunno.

	if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) )

		$cap = $post_type_obj->cap->read_private_posts;



	if ( $full ) {

		if ( null === $post_author ) {

			$sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );

		} else {

			$sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type );

		}

	} else {

		$sql = '';

	}



	$sql .= "(post_status = 'publish'";



	if ( current_user_can( $cap ) ) {

		// Does the user have the capability to view private posts? Guess so.

		$sql .= " OR post_status = 'private'";

	} elseif ( is_user_logged_in() ) {

		// Users can view their own private posts.

		$id = (int) $user_ID;

		if ( null === $post_author || ! $full ) {

			$sql .= " OR post_status = 'private' AND post_author = $id";

		} elseif ( $id == (int) $post_author ) {

			$sql .= " OR post_status = 'private'";

		} // else none

	} // else none



	$sql .= ')';



	return $sql;

}

1574

get_posts

Definition:
function get_posts($args = null) {}

Retrieve list of latest posts or posts matching criteria.
The defaults are as follows: ‘numberposts’ – Default is 5. Total number of posts to retrieve. ‘offset’ – Default is 0. See WP_Query::query() for more. ‘category’ – What category to pull the posts from. ‘orderby’ – Default is ‘post_date’. How to order the posts. ‘order’ – Default is ‘DESC’. The order to retrieve the posts. ‘include’ – See WP_Query::query() for more. ‘exclude’ – See WP_Query::query() for more. ‘meta_key’ – See WP_Query::query() for more. ‘meta_value’ – See WP_Query::query() for more. ‘post_type’ – Default is ‘post’. Can be ‘page’, or ‘attachment’ to name a few. ‘post_parent’ – The parent of the post or post type. ‘post_status’ – Default is ‘publish’. Post status to retrieve.

Parameters

  • array $args: Optional. Overrides defaults.

Return values

returns:List of posts.

Source code

function get_posts($args = null) {

	$defaults = array(

		'numberposts' => 5, 'offset' => 0,

		'category' => 0, 'orderby' => 'post_date',

		'order' => 'DESC', 'include' => array(),

		'exclude' => array(), 'meta_key' => '',

		'meta_value' =>'', 'post_type' => 'post',

		'suppress_filters' => true

	);



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

	if ( empty( $r['post_status'] ) )

		$r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish';

	if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) )

		$r['posts_per_page'] = $r['numberposts'];

	if ( ! empty($r['category']) )

		$r['cat'] = $r['category'];

	if ( ! empty($r['include']) ) {

		$incposts = wp_parse_id_list( $r['include'] );

		$r['posts_per_page'] = count($incposts);  // only the number of posts included

		$r['post__in'] = $incposts;

	} elseif ( ! empty($r['exclude']) )

		$r['post__not_in'] = wp_parse_id_list( $r['exclude'] );



	$r['ignore_sticky_posts'] = true;

	$r['no_found_rows'] = true;



	$get_posts = new WP_Query;

	return $get_posts->query($r);



}

1572

get_postdata

Definition:
function get_postdata($postid) {}

Entire Post data.

Parameters

  • int $postid

Source code

function get_postdata($postid) {

	_deprecated_function( __FUNCTION__, '1.5.1', 'get_post()' );



	$post = &get_post($postid);



	$postdata = array (

		'ID' => $post->ID,

		'Author_ID' => $post->post_author,

		'Date' => $post->post_date,

		'Content' => $post->post_content,

		'Excerpt' => $post->post_excerpt,

		'Title' => $post->post_title,

		'Category' => $post->post_category,

		'post_status' => $post->post_status,

		'comment_status' => $post->comment_status,

		'ping_status' => $post->ping_status,

		'post_password' => $post->post_password,

		'to_ping' => $post->to_ping,

		'pinged' => $post->pinged,

		'post_type' => $post->post_type,

		'post_name' => $post->post_name

	);



	return $postdata;

}

1570

get_post

Definition:
function &get_post(&$post, $output = OBJECT, $filter = 'raw') {}

Retrieves post data given a post ID or post object.
See sanitize_post() for optional $filter values. Also, the parameter $post, must be given as a variable, since it is passed by reference.

Parameters

  • int|object $post: Post ID or post object.
  • string $output: Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
  • string $filter: Optional, default is raw.
  • &$post

Return values

returns:Post data

Source code

function &get_post(&$post, $output = OBJECT, $filter = 'raw') {

	global $wpdb;

	$null = null;



	if ( empty($post) ) {

		if ( isset($GLOBALS['post']) )

			$_post = & $GLOBALS['post'];

		else

			return $null;

	} elseif ( is_object($post) && empty($post->filter) ) {

		_get_post_ancestors($post);

		$_post = sanitize_post($post, 'raw');

		wp_cache_add($post->ID, $_post, 'posts');

	} elseif ( is_object($post) && 'raw' == $post->filter ) {

		$_post = $post;

	} else {

		if ( is_object($post) )

			$post_id = $post->ID;

		else

			$post_id = $post;



		$post_id = (int) $post_id;

		if ( ! $_post = wp_cache_get($post_id, 'posts') ) {

			$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));

			if ( ! $_post )

				return $null;

			_get_post_ancestors($_post);

			$_post = sanitize_post($_post, 'raw');

			wp_cache_add($_post->ID, $_post, 'posts');

		}

	}



	if ($filter != 'raw')

		$_post = sanitize_post($_post, $filter);



	if ( $output == OBJECT ) {

		return $_post;

	} elseif ( $output == ARRAY_A ) {

		$__post = get_object_vars($_post);

		return $__post;

	} elseif ( $output == ARRAY_N ) {

		$__post = array_values(get_object_vars($_post));

		return $__post;

	} else {

		return $_post;

	}

}

1568

get_plugin_updates

Definition:
function get_plugin_updates() {}

Source code

function get_plugin_updates() {

	$all_plugins = get_plugins();

	$upgrade_plugins = array();

	$current = get_site_transient( 'update_plugins' );

	foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {

		if ( isset( $current->response[ $plugin_file ] ) ) {

			$upgrade_plugins[ $plugin_file ] = (object) $plugin_data;

			$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];

		}

	}



	return $upgrade_plugins;

}

1566