Documentation – get_mockingbird()

This function will return related list data. It differs from the mockingbird() function by not rendering any output.

Usage

$related_posts = get_mockingbird( $id, $return_posts, $key );

Parameters

$id (integer) (optional)
The ID of the post from which you want to return data. Use the get_the_id() function while in the loop to get the post’s ID, or use your sub-loop’s post object ID property (eg $my_post_object->ID). You may also use the global $post object ID (eg $post->ID).

Default: none

$return_posts (boolean) (optional)
A boolean value specifying the type of result you wish to return. By default an array of related ids are returned, by setting this value to true an array of related post objects will be returned instead. It should be noted that these results are always returned in the order they were saved. To control the ordering (or any other query parameters), consider using this function to perform you’re own custom Wp_Query() with the returned ids. This will give further control over how results are extracted from WordPress.

Default: false

$key (string) (optional)
A string value to specify the meta key used to retrieve saved mockingbird data. If additional Mockingbird instances have been created, a unique key is required to distinguish it from other instances. Aimed at advanced development, its unlikely that you will need to deviate from the default key during standard development.

Default: ‘sc_mockingbird’

Return Value

  • If $id is left blank the function returns results for the current post, page or custom post type.
  • If $id is specified, the function returns results for the specified post, page or custom post type.
  • If $return_posts is set to false, the function returns an array of related ids.
  • If $return_posts is set to true, the function returns an array of related posts.
  • If $key is specified, the function returns results from that Mockingbird instance.

Examples

Get an array of related ids for the current post.

<?php $related_posts = get_mockingbird(); ?>

Get and array of related post objects for the current post.

<?php $related_posts = get_mockingbird( get_the_id(), true ); ?>

Get and array of related ids for the post with the id of 22.

<?php $related_posts = get_mockingbird( 22, false ); ?>

Use the returned id array to perform a custom WordPress query for the current page.

<?php 
    $args = array(
	    'post__in' => get_mockingbird(),
	    'orderby'=> 'post_title',
	    'order' => 'ASC'
    );
    $related = new Wp_Query($args); 
?>

Get an array of related ids for the post was an id of 5 using a custom key.

<?php $related_posts = get_mockingbird( 5, true, 'testimonials' ); ?>

Notes

  • Values can also be accessed manually using WordPress’s get_post_meta() function and passing ‘sc_mockingbird’ (or a custom key value) as the specified key.
  • Custom titles are stored as separate entries in the post meta table with the suffix ‘_title’. They can be accessed by passing ‘sc_mockingbird_title’ (or a custom key value) as the specified key to the get_post_meta() function.
  • Custom title values are added to each post object returned from this function when $return_posts is set to true.