• All I need and this is not too much to ask is to Query ONE post.

    Problem:

    It’s not a “post” post_type. It’s a custom post_type named “books”.

    Query:

    Post id to get = 10;

    query_posts(‘p=10’); <= THIS DOESN’T WORK
    query_posts(‘post_id’=>10) <= THIS DOESN’T WORK

    I think I know why. because the function query_posts only searches for posts that are have the “post” post_type.

    So I thought.. hey I know how to fix that.

    query_posts(‘post_type’ => ‘books’, ‘p’=>10); <= THAT DOESN’T WORK
    The query above will query all posts in ‘books’ and ignores the post id.

    Please, can someone share how they use query posts to query just one post from a custom post_type?

Viewing 3 replies - 1 through 3 (of 3 total)
  • query_posts(‘p=10’); <= THIS DOESN’T WORK

    Nope, because the ‘p=10’ asks for a normal post with id=10.

    query_posts(‘post_id’=>10) <= THIS DOESN’T WORK

    Nope, because this asks for a normal page with id=10.

    query_posts(‘post_type’ => ‘books’, ‘p’=>10); <= THAT DOESN’T WORK

    Nope, because ‘p’ => 10 asks for a normal post with id=10, overriding the post_type.

    This works for me (with a different id and post_type):

    query_posts(array('post__in' => array(548), 'post_type' => 'parks'));

    Strangely, this does not work:

    query_posts('post_id=548&post_type=parks');  // Gets ALL parks

    Thread Starter gimperdaniel

    (@gimperdaniel)

    That’s what i’ve been telling you.. nothing works.. unless you write your own query… but i just hate mysql “joins”

    Sorry, I didn’t get what you were saying. Is this writing your own query (no joins in sight)?

    query_posts(array('post__in' => array(548), 'post_type' => 'parks'));

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Query_Posts Does Not Work If Post_type is not Post’ is closed to new replies.