get_post_custom

Definition:
function get_post_custom( $post_id = 0 ) {}

Retrieve post meta fields, based on post ID.
The post meta fields are retrieved from the cache, so the function is optimized to be called more than once. It also applies to the functions, that use this function.

Parameters

  • int $post_id: post ID

Source code

function get_post_custom( $post_id = 0 ) {

	$post_id = absint( $post_id );



	if ( ! $post_id )

		$post_id = get_the_ID();



	if ( ! wp_cache_get( $post_id, 'post_meta' ) )

		update_postmeta_cache( $post_id );



	return wp_cache_get( $post_id, 'post_meta' );

}

1585

get_post_comments_feed_link

Definition:
function get_post_comments_feed_link($post_id = 0, $feed = '') {}

Retrieve the permalink for the post comments feed.

Parameters

  • int $post_id: Optional. Post ID.
  • string $feed: Optional. Feed type.

Defined filters

  • post_comments_feed_link
    apply_filters('post_comments_feed_link', $url)

Source code

function get_post_comments_feed_link($post_id = 0, $feed = '') {

	$post_id = absint( $post_id );



	if ( ! $post_id )

		$post_id = get_the_ID();



	if ( empty( $feed ) )

		$feed = get_default_feed();



	if ( '' != get_option('permalink_structure') ) {

		if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )

			$url = _get_page_link( $post_id );

		else

			$url = get_permalink($post_id);



		$url = trailingslashit($url) . 'feed';

		if ( $feed != get_default_feed() )

			$url .= "/$feed";

		$url = user_trailingslashit($url, 'single_feed');

	} else {

		$type = get_post_field('post_type', $post_id);

		if ( 'page' == $type )

			$url = home_url("?feed=$feed&page_id=$post_id");

		else

			$url = home_url("?feed=$feed&p=$post_id");

	}



	return apply_filters('post_comments_feed_link', $url);

}

1583

get_post_class

Definition:
function get_post_class( $class = '', $post_id = null ) {}

Retrieve the classes for the post div as an array.
The class names are add are many. If the post is a sticky, then the ‘sticky’ class name. The class ‘hentry’ is always added to each post. For each category, the class will be added with ‘category-‘ with category slug is added. The tags are the same way as the categories with ‘tag-‘ before the tag slug. All classes are passed through the filter, ‘post_class’ with the list of classes, followed by $class parameter value, with the post ID as the last parameter.

Parameters

  • string|array $class: One or more classes to add to the class list.
  • int $post_id: An optional post ID.

Return values

returns:Array of classes.

Defined filters

  • post_class
    apply_filters('post_class', $classes, $class, $post->ID)

Source code

function get_post_class( $class = '', $post_id = null ) {

	$post = get_post($post_id);



	$classes = array();



	if ( empty($post) )

		return $classes;



	$classes[] = 'post-' . $post->ID;

	$classes[] = $post->post_type;

	$classes[] = 'type-' . $post->post_type;

	$classes[] = 'status-' . $post->post_status;



	// Post Format

	if ( post_type_supports( $post->post_type, 'post-formats' ) ) {

		$post_format = get_post_format( $post->ID );



		if ( $post_format && !is_wp_error($post_format) )

			$classes[] = 'format-' . sanitize_html_class( $post_format );

		else

			$classes[] = 'format-standard';

	}



	// post requires password

	if ( post_password_required($post->ID) )

		$classes[] = 'post-password-required';



	// sticky for Sticky Posts

	if ( is_sticky($post->ID) && is_home() && !is_paged() )

		$classes[] = 'sticky';



	// hentry for hAtom compliance

	$classes[] = 'hentry';



	// Categories

	if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {

		foreach ( (array) get_the_category($post->ID) as $cat ) {

			if ( empty($cat->slug ) )

				continue;

			$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);

		}

	}



	// Tags

	if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {

		foreach ( (array) get_the_tags($post->ID) as $tag ) {

			if ( empty($tag->slug ) )

				continue;

			$classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);

		}

	}



	if ( !empty($class) ) {

		if ( !is_array( $class ) )

			$class = preg_split('#\s+#', $class);

		$classes = array_merge($classes, $class);

	}



	$classes = array_map('esc_attr', $classes);



	return apply_filters('post_class', $classes, $class, $post->ID);

}

1581

get_post_ancestors

Definition:
function get_post_ancestors($post) {}

Retrieve ancestors of a post.

Parameters

  • int|object $post: Post ID or post object

Return values

returns:Ancestor IDs or empty array if none are found.

Source code

function get_post_ancestors($post) {

	$post = get_post($post);



	if ( !empty($post->ancestors) )

		return $post->ancestors;



	return array();

}

1578

get_posts_nav_link

Definition:
function get_posts_nav_link( $args = array() {}

Return post pages link navigation for previous and next pages.

Parameters

  • string|array $args: Optional args.

Return values

returns:The posts link navigation.

Source code

function get_posts_nav_link( $args = array() ) {

	global $wp_query;



	$return = '';



	if ( !is_singular() ) {

		$defaults = array(

			'sep' => ' — ',

			'prelabel' => __('« Previous Page'),

			'nxtlabel' => __('Next Page »'),

		);

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



		$max_num_pages = $wp_query->max_num_pages;

		$paged = get_query_var('paged');



		//only have sep if there's both prev and next results

		if ($paged < 2 || $paged >= $max_num_pages) {

			$args['sep'] = '';

		}



		if ( $max_num_pages > 1 ) {

			$return = get_previous_posts_link($args['prelabel']);

			$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']);

			$return .= get_next_posts_link($args['nxtlabel']);

		}

	}

	return $return;



}

1576