0

On my Wordpress-website, I have a custom post type used to display events and a page showing all events in the database. On that page, I'm creating a new WP_Query and displaying the results immediately afterwards.

    $q_events = new WP_Query(array('post_type' => 'lc_events', 'orderby' => 'ID'));
    if ($q_events->have_posts()) : while ( $q_events->have_posts() ) : $q_events->the_post(); ?>
        <div class="activiteit">
                <?php ...

``

However, the orderby-option doesn't work, no matter what option I'm actually ordering by. In the code above you see ID, but I have also tried title and meta values (using 'meta_key' => 'lc_events_startdate', 'orderby' => 'meta_value', 'order' => 'ASC'. I have yet to figure out in what order events are actually displayed, but have ruled out ID, title, two of my meta values (lc_events_startdate and lc_events_enddate) and post date/time.

I know that orderby was changed in WP4.0, but cannot determine whether my problem is caused by a bug, or by an error in my coding.

EDIT (October 3): WP_DEBUG is set to true, and only shows a notice concerning a script in my sidebar, nothing regarding the WP_Query.

Thanks for all help,

Bram

closed as off-topic by fuxia Oct 4 '14 at 14:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • That is strange. Are you getting any debug errors. What hapens if you switch to a bundled theme and run the same query. Have you tried reinstalling wordpress? – Pieter Goosen Oct 1 '14 at 11:58
  • I think the WP_Query is right. Do you have set WP_DEBUG that you get error messages. But maybe you check the follow syntax to add the ascending: new WP_Query( array( 'post_type' => 'lc_events', array( 'orderby' => array( 'id' => 'DESC' ) ) ) ); – bueltge Oct 1 '14 at 12:01
  • No debug errors related to these scripts. Adding the code @bueltge proposed does not make a difference. – Bram Oct 3 '14 at 12:41
  • Have you tried dumping the $q_events variable and looking at the SQL it produces? The SQL used for the query will be in there and you can see what the result of changing the orderby actually is. – Otto Oct 3 '14 at 14:00
  • Thanks @Otto for that suggestion. I tried it, and it lead me to the error. There apparently was a plug-in interfering with the sorting. Fixed now! – Bram Oct 4 '14 at 12:54
0

There was nothing wrong with the query or the core Wordpress-code, but a plug-in was in the way. Thanks for all help and good advice!

-2

Please try this way, may help you.

        $myPageQuery= new WP_Query( 'cat=7&orderby=date&order=ID&showposts=1' );

Thanks

  • I'm pretty sure that the OP will have a different category ID assigned. Please explain why your answer will help - in an edit. Thank you. – kaiser Oct 3 '14 at 8:32
  • Tried this method of setting up the query arguments using new WP_Query('post_type=lc_events&orderby=ID'), but it doesn't make a difference. – Bram Oct 3 '14 at 12:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.