0

I'm having a strange issue with sorting by post date.

I created a slideshow post type and it does by default order by post date but If I change the date posted through the admin the order doesn't update in the query, but it does get updated in the admin.

The Post Type

/* Slideshow Post Type */
add_action('init', 'slide_init');
function slide_init() {
    $labels = array(
        'name' => _x('Slides', 'post type general name'),
        'singular_name' => _x('Slide', 'post type singular name'),
        'add_new' => _x('Add New', 'slide'),
        'add_new_item' => __('Add New Slide'),
        'edit_item' => __('Edit Slide'),
        'new_item' => __('New Slide'),
        'view_item' => __('View Slide'),
        'search_items' => __('Search Slides'),
        'not_found' => __('No slides found'),
        'not_found_in_trash' => __('No slides found in Trash'), 
        'parent_item_colon' => '',
        'menu_name' => 'Homepage Slides'
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title', 'editor', 'thumbnail')
    ); 
    register_post_type('slide', $args);
}

The Query

// Slideshow Query
$slideshow_args = array(
    'post_type' => 'slide',
    'posts_per_page' => '10',
);
$slideshow = new WP_Query( $slideshow_args );

Edit - -

I found out this has something to do with this line of code.

$slideshow_post_count = $slideshow->post_count; 

<?php if ($slideshow_post_count > 1) : ?>
<div class="controls span6">
    <span class="next"></span>
    <span class="pause"></span>
    <span class="prev"></span>
</div>
<?php endif; ?>
5
  • Sounds like you got something modifying your query elsewhere. Plugin?
    – GhostToast
    Commented Aug 22, 2013 at 17:10
  • That's what I thought I removed them all. It orders in a very strange way. It will make a post first sometimes when I change the date manually. I tested and right now the order is Aug21, Aug17, Aug18. It still updates some posts when I change the date so this must be part of the query. I should mention I just updated to 3.6.
    – hyperdrive
    Commented Aug 22, 2013 at 17:18
  • @GhostToast I found If i remove the line above the query runs normally, but I don't know how else I could include this?
    – hyperdrive
    Commented Aug 22, 2013 at 17:31
  • I tried replacing post_count with found_posts, same issue.
    – hyperdrive
    Commented Aug 22, 2013 at 17:33
  • i'd be var_dumping the wp_query object to see what it was really trying to do. No caching, all plugins disabled?
    – GhostToast
    Commented Aug 22, 2013 at 17:35

1 Answer 1

0

Have you played with the other arguments available to WP_Query?

$slideshow_args = array(
    'post_type' => 'slide',
    'posts_per_page' => '10',
    'orderby'        => 'post_date',
    'order'          => 'DESC'
);
$slideshow = new WP_Query( $slideshow_args );
4
  • It's something with my controls. See my edit.
    – hyperdrive
    Commented Aug 22, 2013 at 18:02
  • Hmm I think you may be onto the right path but it's not the controls themselves. Can you remove all control code and try printing out the titles and dates raw to narrow it down? Commented Aug 22, 2013 at 18:07
  • I'm the biggest idiot, my controls are backwards... Thanks for your help anyhow.
    – hyperdrive
    Commented Aug 22, 2013 at 18:16
  • Glad you figured it out, I know your pain. If I helped at all please mark my answer correct. Commented Aug 22, 2013 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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