get_posts() With Custom Meta Tag
-
I have a quick question about the get_posts() function – I can’t seem to get it to return anything.
I created a custom meta tag for a page and tagged it as “MetaTag”. In the page’s PHP, I first grab the meta information and display it (works fine), and then I try to grab pages based on them matching that meta information, and I can’t seem to get that to work.
What I have is the following:
$my_meta = get_post_meta($post->ID,'_my_meta',TRUE); echo "Current page's meta tags: ".$my_meta['name']."<br />"; $args = array( 'meta_query' => array( array( 'name' => 'MetaTag', ) ) ); $postslist = get_posts( $args ); echo "Post list: ".$postlist;
The first echo command yields: “Current page’s meta tags: MetaTag”, as it should. However, the second echo command yields “Post list: “, but the actual return of $postlist is blank. My goal is to get it to say “Post list: 89”, i.e. return the post ID’s of the posts who have the correct meta tag. I assume this is just a basic misuse of the get_posts() function, but I’m not sure where I’m going wrong.
- The topic ‘get_posts() With Custom Meta Tag’ is closed to new replies.