0

I am attempting to use get_posts() to retrieve posts that have certain topics attached to them, in my custom post type named 'leaders'

Here is my query.

$args = array(
    'post-type' => 'leaders',
    'meta_query' => array(
    array(
     'key' => 'topics',
     'value' => '1773',
     'compare' => 'LIKE'
    )
)
);

$test = get_posts( $args );

If I var_dump the posts meta data i get this

topics  a:4:{i:0;s:4:"1773";i:1;s:4:"1783";i:2;s:4:"1763";i:3;s:4:"1753";}

However my get_posts just returns null, can anyone see why?

1 Answer 1

1

One problem here is that you have written post-type with a hyphen when it should be with an underscore, like this post_type.

So, this should get your post data back:

$args = array(
    'post_type' => 'leaders',
    'meta_query' => array(
        array(
            'key' => 'topics',
            'value' => '1773',
            'compare' => 'LIKE'
        )
    )
);

$test = get_posts( $args );
1
  • Welcome to WPSE. Good spot ;-) Commented Feb 25, 2016 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.