WordPress.org

Ready to get started?Download WordPress

Forums

query_posts returns varying results on same page (3 posts)

  1. kalico
    Member
    Posted 7 years ago #

    I have a customized Page template which has long worked just fine, which suddenly is not displaying the way it should. I am pretty sure that the query_posts call is the root of the problem, but I'm open to other ideas.

    The page in question has several drop-down lists of posts, generated by custom queries. The lists should all be populated (they used to be, and I haven't touched the code), but only some of them are.

    The really frustrating thing is that I can't find anything in common between the categories whose posts are NOT showing up. I'm at my wit's end, and can't figure out what else to even look at.

    There are several identical queries on this page, the only difference is in which category each query draws it's information from (category_ID is based on category_parent).

    Here is an example:

    $results = $wpdb->get_results("SELECT cat_ID, cat_name,
    category_nicename, category_description, category_parent
    FROM ".$wpdb->categories."
    WHERE category_description != '' AND
     category_parent = '39' ORDER BY cat_my_order ");

    The difference is in the category_parent for each query.

    If you're looking at the page, the first two drop downs (Genesis, Elijah and Elisha) are both generated by the same custom query. One displays, the other does not.

    The next two (Who is Jesus, Luke's Parable) are generated by a different query (essentially the same query, but these two share a different parent category, so they are displayed separately). Neither one of them is displaying.

    The next three (Romans, James, Revelation) are generated by another identical query: all three are working fine.

    Then in the final query (responsible for Holidays, My Passions, Work), all the category drop downs are displaying posts, except one of them (My Passions).

    Probably the best way to see all this is in the pastebin, so http://wordpress.pastebin.com/m2d7ca605 is the complete code for the custom Page template.

    I ran Jerome's Query Diagnostics, and here is the result of loading the template page: http://wordpress.pastebin.com/m5c975cc8

    I haven't installed any new plugins recently, but for the sake of argument, the list of plugins I'm using is here: http://www.timelessword.com/about/wordpress-plugins-used/

    If I can supply any further helpful information I'd be happy to. I'm grateful for any suggestions as to where to look for the root of this problem.

  2. morty
    Member
    Posted 7 years ago #

    Did you run the queries in phpMyAdmin? Also you can var_dump $result and see, whether you get the expected results.

  3. Brian Layman
    Member
    Posted 7 years ago #

    It looks fine. Without having access to the data I'd have a really hard time debugging this.

    One suggestion, change category_description != '' to category_description > '' That way you don't get any categories that are NULL (AKA EMPTY or uninitialized as far as this conversation is concerned) which sure looks like '' but doesn't compare the same.

Topic Closed

This topic has been closed to new replies.

About this Topic