Title: Custom WP_query
Last modified: April 21, 2021

---

# Custom WP_query

 *  Resolved [raphaelw](https://wordpress.org/support/users/raphaelw/)
 * (@raphaelw)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/custom-wp_query-2/)
 * Hi guys,
 * Thank you for this great plugin, i installed it one year ago and it used to work
   perfectly for me with my custom needs until the last plugin update (5.3.1).
 * I run a custom WP_query on my frontpage returning the most popular custom post
   types (weekly), using this code : [How To: Sorting a custom query by views (All time, monthly, weekly, or daily)](https://wordpress.org/support/topic/how-to-sorting-a-custom-query-by-views-all-time-monthly-weekly-or-daily/)
   in my functions.php
 * It was working great until last update, but now, the posts displayed are not 
   matching with the most populars anymore.
 * My query looks like :
 *     ```
       $args = array('meta_key' => 'views_weekly', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => 15, 'post_type' => 'guide');
       $popularPostsQuery = new WP_query( $args );
       ```
   
 * And the code in functions.php is :
 *     ```
       function custom_wpp_update_postviews($postid) {
           $accuracy = 30;
           if ( function_exists('wpp_get_views') && (mt_rand(0,100) < $accuracy) ) {
               update_post_meta(
                   $postid,
                   'views_weekly',
                   wpp_get_views($postid, 'weekly', false)
               );
           }
       }
       add_action('wpp_post_update_views', 'custom_wpp_update_postviews');
       ```
   
 * Do you have any idea about where this recent issue comes from?
 * Thank you
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-wp_query-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/custom-wp_query-2/#post-14346180)
 * Hi [@raphaelw](https://wordpress.org/support/users/raphaelw/),
 * Glad to know that WPP has been useful to you so thanks for the kind words.
 * Regarding your issue, it’s probably related to [this](https://wordpress.org/support/topic/conflict-counter-views-script-older-post/).
   Please give the solution I shared there a try and let me know if it fixes the
   problem for you.
 *  Thread Starter [raphaelw](https://wordpress.org/support/users/raphaelw/)
 * (@raphaelw)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/custom-wp_query-2/#post-14346260)
 * Hi Héctor,
 * Thank you so much, i haven’t seen this post despite my searches.
    Great, it looks
   like it works again 🙂
 * I temporarily changed the accuracy parameter to 100 in order to see it in action.
 * Thanks again for your pretty good work and such nice support!
 * Best
    -  This reply was modified 4 years, 11 months ago by [raphaelw](https://wordpress.org/support/users/raphaelw/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom WP_query’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

## Tags

 * [wpp_get_views](https://wordpress.org/support/topic-tag/wpp_get_views/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 2 replies
 * 2 participants
 * Last reply from: [raphaelw](https://wordpress.org/support/users/raphaelw/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/custom-wp_query-2/#post-14346260)
 * Status: resolved