Support » Theme: GeneratePress » get popular post of a week updated based on view count

  • Resolved ysgmesh

    (@ysgmesh)


    I used this code `<?php
    //Set the parameters / arguments for the query
    $popular_post_args = array(

    ‘meta_key’ => ‘post_views_count’, //meta key currently set
    ‘orderby’ => ‘meta_value_num’, //orderby currently set
    ‘order’ => ‘DESC’, //order currently set
    ‘posts_per_page’ => 10, // show 2 posts
    ‘date_query’ => array( // date query from after 1 week ago
    array(
    ‘after’ => ‘1 week ago’,
    ),
    ),
    );

    //Initialise the Query and add the arguments
    $popular_posts = new WP_Query( $popular_post_args );

    //Check if theres posts and add your html divs around it
    if ( $popular_posts->have_posts() ) : ?>

    <?php
    //Start the loop
    while ( $popular_posts->have_posts() ) : $popular_posts->the_post(); ?>` on my site to get popular post of a week but the problem is that it is not functioning properly. Please is there any way I can update this posts each time any post view increases it will automatically list it as the most viewed in a week not regarding if the post is just published. Please this is really the last thing bordering me on my site tophits
    Thanks in advance.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    This isn’t really something I’m able to help with much here, as it’s not directly related to the theme.

    I would make sure your post meta key is correct. Also, maybe try removing the date query just for now to see if it’s causing any issues.

    Thread Starter ysgmesh

    (@ysgmesh)

    Thanks for your reply… I will really be glad if this can work for me. I have struggled with this for sometime now and not gettting it updates accordingly and I dont like using plugins to do that. Please if there is any chance and you could point me on the right way to get all popular post in a week and reset it as new post get more view I will be glad. Just one of the last things remaining on my website. Thanks

    Theme Author Tom

    (@edge22)

    It’s a difficult thing to debug through the forum. Did you try what I said? Do you get any results at all? Or does it display nothing?

    Thread Starter ysgmesh

    (@ysgmesh)

    oh…thanks for your reply dear. I tried removing what you said but when removed it reverts to outputting latest post in order which is not what I want. Please if you have any argument that can output most viewed post like https://wordpress.org/plugins/top-10/ please give me. I will do the styling myself. Please I am in need of this code that can work because I have looked for it so many places with no positive result. If you check the top 10 guy he dropped some API for the plugin which am still trying to know if I could get it work without installing plugins this is because I want to limit my plugin. Please do take a look on my site tophits and tell me if this is not possible so I will mark this thread either solved or not supported. I really appreciate your help and support on this forum.

    • This reply was modified 2 years, 10 months ago by ysgmesh. Reason: added a useful link
    Theme Author Tom

    (@edge22)

    Why not use this plugin?: https://wordpress.org/plugins/top-10/

    Looks like it should do exactly what you’re wanting?

    Thread Starter ysgmesh

    (@ysgmesh)

    I know about top-10 but it slows my site so badly… My site scores above 90 on google page speed test and I will not like anything below 90. If I install top-10 plugins it drags my site down so badly. So I want to avoid plugins unless there is another way that I can install it outside plugin installation folder. If I can integrate it inside theme I would have done it but I dont know how yet. At this point I like the way I use child theme for generatepress except this last part that is really messing me up. I am still searching for a way to achieve this task exactly like https://wordpress.org/plugins/top-10/ without installing the plugins.

    Theme Author Tom

    (@edge22)

    You may need to hire a developer to integrate something similar. A service like codeable.io might be worth checking into.

    Loading a plugin in the plugin folder vs in a theme is the same thing – code is code, whether it’s a plugin or theme. I’m not sure why a plugin like that would cause performance issues, but it may be worth checking with the author.

    Thread Starter ysgmesh

    (@ysgmesh)

    Please note that I have resolved this issue by myself. Thanks.

    Theme Author Tom

    (@edge22)

    Awesome! 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘get popular post of a week updated based on view count’ is closed to new replies.