• Hello, I’m using “query_posts” inside a plugin (into a function called with each post).

    The goal of that plugin is to find related informations to the post.

    It’s working in AJAX; I get the ID of the post with ajax that I send to a function :

    function folio_mk_infos_getlist($id) {

    then I use

    `$post = query_posts(‘p=’.$id);

    So I “build” the usual object $post (access to $post->… vars)

    It’s working perfectly, but the problem is that the query_posts function seems to reset my original query; and so in wordpress the first post is repeated over and over again.
    I tryed to put the $wp_query var in a temp var and calling back at the end of my plugin function, but it does not work.

    How can I do this little trick ?

    Thanks !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Best way to do what you want is to not use query_posts, but to create a new WP_Query() instead. There’s examples of this in the codex, search for “The Loop”.

    In your case, it seems that you just want to get a specific post by ID. So you might just want to use the get_post() function instead. No messing about with query building that way.

    However, you can also get your original query back by calling wp_reset_query().

    Anyone have any idea why query_posts with cat=-15 is returning my posts in ascending order? I thought it could have been related to the MySQL problem discussed here, but I’ve ruled that out. Here is the code I’ve been using since WP 2.3

    query_posts($query_string . '&cat=-15');

    This was effectively removing my ‘front_page’ category from my author pages. This worked just fine until sometime after I upgraded to the RC-1 version of WP 2.5. Shortly after (unfortunately I wasn’t looking at these author pages very closely until nearly a week after the upgrade) I upgraded to WP 2.5 RC-1, this query_posts started returning the posts in reverse order.

    In an attempt to work-around this issue, I tried the following:

    query_posts($query_string . '&cat=-15&order=DESC')

    This seemed to just completely ignore the DESC order request. Next I tried this:

    query_posts($query_string . '&order=DESC&showposts=3')

    Without the cat=-15, the query returns the posts in the correct order. I played around with it with lots of different combinations of queries, and it seems that any time cat=-# is put into the query_posts, it returns the posts in reverse order.

    Anyone know a fix for this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts seems to reset my query !!!’ is closed to new replies.