• I have a custom post type set up for listing some exhibitors for trade shows and events. I can add, edit, delete the posts, as well as preview and publish them. The problem comes in my loop, when ordering the posts. I have a shortcode set up to be able to insert the exhibitor listing into pages or posts. If I set any “orderby” attribute, besides ‘id’, then some of the records are not displayed, unless I’m logged in with an admin account. I’ve verified that the posts are all marked as “published” and “public”, but no dice. When I order by ‘id’ they all show up, but they need to be ordered alphabetically by title in order to be usable.

    $args = array(
    	'post_type' => 'exhibitor',
    	'orderby' => 'id',
    	'order' => 'ASC',
    	'posts_per_page' => -1,
    	'meta_key' => 'event',
    	'meta_value' => '<event_id>', //event ID entered based on shortcode attribute
    	'meta_compare' => '!=' //show all but this event -- this is correct behavior for my needs
    );
    query_posts($args);

    It seems that any posts after a certain date are the ones that are left out when ordering by title, so the most recent entries (any past about July 1st, it seems) are not visible on the frontend unless I’m logged in as an admin, so the public are unable to see them.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try WP_Query Instead, Query_Posts is used to alter an existing query, not to create a new one

    Not for Secondary Loops
    You should not use query_posts() to create secondary listings (for example, a list of related posts at the bottom of the page, or a list of links in a sidebar widget).

    Instead, you should make a new instance of WP_Query or use get_posts().

    HTH

    David

    Thread Starter Quentin

    (@egojab)

    That didn’t solve it, though I’m glad you pointed it out, because it is good practice. The query_posts code was left in from previous functionality within a template. It’s good to have it written properly. Poor work on my part.

    The problem persists though. When sorting by id everything works fine. When sorting by title, certain posts simply do not show up. Both ways work correctly when logged in as an admin, but not when not logged in.

    Both ways work correctly when logged in as an admin, but not when not logged in.

    This looks like a cache issue, do you have a page caching plugin, which is set to not cache for logged in users?

    David

    Thread Starter Quentin

    (@egojab)

    No, no caching plugins installed.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘query_posts oderby title causes items to not display for users’ is closed to new replies.