[Support request] Display most visited posts WP_Query

Home Forums Support [Support request] Display most visited posts WP_Query

Home Forums Support Display most visited posts WP_Query

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1375142
    Hilton

    Hello,

    I currently use a WP_Query to display the most recent articles using a shortcode.

    The WP_Query is this one:

    $the_query = new WP_Query( array(
    ‘cat’ => $category->term_id,
    ‘posts_per_page’ => 5,
    ‘order’ => ‘desc’,
    ‘orderby’ => ‘modified’
    )

    I would like to know if, to display the most visited articles instead of the most recent ones, I could use this WP_Query here:

    $the_query = new WP_Query( array(
    ‘cat’ => $category->term_id,
    ‘posts_per_page’ => 5,
    ‘meta_key’ => ‘post_views_count’,
    ‘orderby’ => ‘meta_value_num’
    )

    Thanks

    #1375288
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You could, but you’d need something to add to that custom field count each time someone visits your site.

    Something like this may help: https://wordpress.org/plugins/advanced-page-visit-counter/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.