• Resolved jenseo

    (@jenseo)


    Hi!

    First of all, thanks for a great plugin! I posted this question on the github page, but then I realised that the plugin was listed here again, so I decided to post it here as well. I guess it’s the more appropriate place.

    This is my code to fetch child posts inside a single post template, which works, except for one thing:

    <?php
    $initial_count = get_post_meta($post->ID, '_initial_count', true);
    $images = get_children('post_parent='.$post->ID.'&post_status=publish&post_type=user_images');
    if ( ! empty( $images ) ) {
        $image_ids = wp_list_pluck( $images, 'ID' );
        $image_ids = implode(',',$image_ids);
     echo do_shortcode('[ajax_load_more post_type="user_images" preloaded="true" preloaded_amount="'.$initial_count.'" meta_key="_point" post__in="'.$image_ids.'" orderby="meta_value_num" posts_per_page="20" pause="true" scroll="false" button_label="Ladda fler bilder..." transition="fade" container_type="div" css_classes="user-images"]');
    }
    wp_reset_postdata();
    ?>

    Users can vote for posts on my site, and what I’m trying to do is to order the posts by the meta key “_point” (the number in this custom field).

    It works for the preloaded posts, but when I load more, sometimes it displays some of the same posts as in the preloaded list.

    I think there might be two possible explanations for this:

    It could be a cache related issue, although I don’t think that would be the case.

    or…

    It could be that I also need to specify that it should posts with the same number of votes by publish date/time. Something like this:

    $query->set('orderby', array('meta_value_num' => 'DESC', 'date' => 'DESC'));
    Would this be possible?

    // Jens.

    https://wordpress.org/plugins/ajax-load-more/

Viewing 6 replies - 16 through 21 (of 21 total)
Viewing 6 replies - 16 through 21 (of 21 total)

The topic ‘Query by meta_value_num and date?’ is closed to new replies.