Great plugin!
I’m trying to display today most viewed post with desc order. i tries this shortcode
[display-posts posts_per_page=”10″ wrapper=”ul” wrapper_class=”latest_news_style” date_query_after=”-1 days” date_column=”post_modified” orderby=”meta_value_num” meta_key=”post_views_count” order=”DESC”]
I made new page and set there query which should show most popular posts weekly.
$query = new WP_Query( array( 'paged' => get_query_var('paged'), 'meta_key' => 'views_weekly', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );
But it is clearly showing wrong posts (not the most popular). Ive got also widget at sidebar with popular posts :
$args = array( 'limit' => 20, 'range' => 'weekly', 'stats_views' => 0, 'post_type' => 'post');
wpp_get_mostpopular( $args );
And this widget is showing correctly the most visited posts. And I cant find out why these 2 queries are showing me completely different posts.
I set sample rate 30% for both the plugin settings and function saving views to meta fields, so the number of views at metafields is the same as on plugin settings page. So why does wordpress doesnt order those posts correctly ?
Thank you
]]>The array that I build using WP_Query is in the correct order. However when I use the IDs in post_in parameter it is not displaying them in the given order. I have also tried to give orderby=”meta_value_num” parameter but it doesnt work either.
Here is WP_QUERY which is working perfectly
`$loop = new WP_Query(
array(
‘post_type’ => ‘properties’,
‘posts_per_page’ => -1,
‘meta_query’ => array(
array(
‘key’ => ‘listing_type’,
‘value’ => array(3,2),
‘type’ => ‘NUMERIC’,
),
array(
‘key’ => ‘payment_status’,
‘value’ => ‘yes’,
),
array(
‘key’ => ‘expired’,
‘value’ => ‘no’,
),
),
‘orderby’ => ‘meta_value_num’,
‘meta_key’ => ‘listing_type’,
‘order’ => ‘DESC’
));
Here is the shortcode:
[ajax_load_more post_type=”properties” post__in=”‘.implode(‘,’,$featured).'” posts_per_page=”10″ scroll=”false” transition=”fade” button_label=”‘.$l_more.'” button_loading_label=”‘.$l_more_2.'” container_type=”ul” css_classes=”items”,orderby=”meta_value_num” meta_key=”listing_type”]
However it doesnt order posts as it should because $featured array has it in required order. Even if I remove order by and meta_key parameter it doesnt work.
Please Help
Ahmar
Based on this person’s post (and the author’s reply), I was able to get FPW to work for me:
https://www.ads-software.com/support/topic/custom-filed-integration/
I have a custom plugin I use to hold functions like this so I don’t deal with my theme’s functions.php, but here is the code I added to get it to sort:
<?php
/* Adjust Flexible Posts Widget to order by meta_key */
add_filter( 'dpe_fpw_args', 'pcva_fpw_sortmeta' );
function pcva_fpw_sortmeta($query) {
// The value in meta_key is my custom field's name
$query['meta_key'] = 'hidden_sort_value';
// The value in orderby is 'meta_value_num', which means sort it as a number. 'meta_value' would sort it as alphanumeric.
$query['orderby'] = 'meta_value_num';
return $query;
}
I’ve been looking for this a long, long time, and since I got it working, I thought I’d share.
]]>When I try and order by this hidden_value, it sorts alphabetically. 90,000 is above 40,000,000 because 9 comes first (in descending order).
I’ve made it work by modifying a few things in the plugin manually:
Changed references to “meta_value” to “meta_value_num” in the main plugin file.
Changed same reference in wp_options here: s:14:”meta_value_num”
This works for what I want it to do. But when the plugin gets updated, I have to manually tweak it again.
Is there any way this can be updated to add another Order By that is “Custom Field (Num)”?
I would be eternally grateful.
Thanks.
]]>Rather then sorting as expected it seems to be sorting the posts as if i were using meta_value. I have 3 price points and it is sorting:
10, 1, 5 rather then 10, 5, 1.
Below is my code
$args2 = array( 'post_type' => 'instant_game_page', 'orderby' => 'meta_value_num', 'meta_key' => $instants_mb->the_value('cost'), 'order' => 'DESC', 'category_name' => $slug, );
Any help or suggestions would be greatly appreciated. Thanks
]]>1. Store the view counts for different time frames, for each post, as a meta key.
This code can go in your functions.php file. Mind the comments – they will help keep your website performing well.
/* Storing views of different time periods as meta keys */
add_action( 'wpp_post_update_views', 'custom_wpp_update_postviews' );
function custom_wpp_update_postviews($postid) {
// Accuracy:
// 10 = 1 in 10 visits will update view count. (Recommended for high traffic sites.)
// 30 = 30% of visits. (Medium traffic websites)
// 100 = Every visit. Creates many db write operations every request.
$accuracy = 50;
if ( function_exists('wpp_get_views') && (mt_rand(0,100) < $accuracy) ) {
// Remove or comment out lines that you won't be using!!
update_post_meta( $postid, 'views_total', wpp_get_views( $postid ) );
update_post_meta( $postid, 'views_daily', wpp_get_views( $postid, 'daily' ) );
update_post_meta( $postid, 'views_weekly', wpp_get_views( $postid, 'weekly' ) );
update_post_meta( $postid, 'views_monthly', wpp_get_views( $postid, 'monthly' ) );
}
}
—
2. Create a new WP_Query, sort by view counts within the last week
You can change this to all time, daily, or monthly. Just change the meta key. If you want this to affect the main query, it’s better to modify the default query using the pre_get_posts filter.
// Get the 3 top viewed posts for the week.
$args = array(
'post_type' => 'post',
'meta_key' => 'views_weekly',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => '3',
);
$top_posts = new WP_Query($args);
—
3. Populate the meta keys for immediate use
If you enter the code above, you’ll notice #2 doesn’t work. This is because the meta keys for each post aren’t added until the view count updates. To do this, set $accuracy to 100% and view each post manually. This will populate the meta keys.
You only need to do this step once. When you are done, change the $accuracy again.
https://www.ads-software.com/plugins/wordpress-popular-posts/
]]>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://www.ads-software.com/plugins/ajax-load-more/
]]>I am using the plugin to order by meta_value_num with a meta_key parameter which works great. Below is the code.
[ajax_load_more post_type="post" orderby="meta_value_num" meta_key="total_views" scroll="false" posts_per_page="3" button_label="Load more"]
What I would like to achieve is to only show the posts that were added in the last X no of days (X can be 10 as an example and then it would show only the posts in the last 10 days) or otherwise after a certain date (eg: 2015/08/10 as it would be in this request: https://www.ads-software.com/support/topic/filter-by-post_date?replies=2).
Can you please let me know if there is a way to achieve this using the plugin? And if it can be done how to adjust the shortcode.
Thanks,
Alin
https://www.ads-software.com/plugins/ajax-load-more/
]]>I’ve created a custom post type, with post meta. The field name is ‘price_two’. This field contains float values such as :
11.95
13.50
9.23 etc
Now when using this query:
$query = new WP_Query(
array(
'post_type'=>'product',
'types' => $term->slug,
'orderby' => 'meta_value_num',
'meta_key' => 'price_two',
'order' => 'ASC',
'paged' => $paged
)
);
It returns the posts sorted as if sorted by a string. I’ve attempted multiple ways around this I’ve found in Google, such a putting meta_value in front of meta_value_num.
The values are currently sorted for example, in this order:
9.95
12.95
11.95
14.95
16.95
13.95
Is there a way around this? essentially i need it to be sorted based on the float value.
]]>