Support

Account

Home Forums Front-end Issues Adding field into a query_posts, need help.

Solving

Adding field into a query_posts, need help.

  • I’m trying to query a custom field ‘blog_category_id’ that I added to a ‘shows’ post type, this is going to display a series of blog posts based on the blog category id.

    <?php $blog_category_id = get_field('blog_category_id');
    query_posts('showposts=4&cat='.$blog_category_id.'&ignore_sticky_posts=1');
    if(have_posts()) : while(have_posts()) : the_post(); ?>

    Is what I’ve tried to use but it isn’t working properly, however, I’ve echo’d $blog_category_id and it displays the proper number so I’m not sure what I’m doing wrong here.. I’ve included a pastebin with the entire pages code: http://pastebin.com/Ly8aZzPY

    I’ll try and explain what this full page is supposed to be doing:

    The page displays all of the ‘show’ content type posts, inside of each post it grabs a user filled field blog_category_id and displays the 4 most recent blog posts from that category.

    Help is greatly appreciated, thank you!

  • Hi @Klikster

    I think the issue is that you are using the query_posts function within a custom WP_Query loop. Why have you mixed both ways to query posts?

    I would always use the WP_Query method, never the query_posts.

    Good luck,

    Thanks
    E

  • Hi Elliot,

    I’m a pretty novice coder so I don’t really understand the difference between them. I’ll try updating it to WP_Query and post back here if I need more assistance? Thanks. 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Adding field into a query_posts, need help.’ is closed to new replies.