Query by meta_value_num and date?
-
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.
-
Sorry, it seemed resolved, but unfortunately not. It still duplicates posts when loading more.
You can see it in action here:
https://delbart.se/sveriges-basta-podcasts/
Look for images that look the same, no posts have the same image. The post can have the same point though.
Can you please post your repeater template?
Im starting to think you have missed the instructions to always open and close your repeater templates with an HTML element.
This might have something to do with your issue.
<div> //content </div>Yes, I did miss this…
<h2><?php echo '#' . $alm_item . '.'; ?> <?php the_title(); ?></h2> <?php the_content(); ?>Will try to wrap it!
Thanks dcooney, that seems to have done the trick! Sorry about the trouble, I had totally missed that part!
Nice! Thanks for reporting back!
The topic ‘Query by meta_value_num and date?’ is closed to new replies.