Jump to content

I am trying to modify this code to show only most viewed post in 7 days instead of all time


Recommended Posts

<?php query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul class="rpul"> <li> <div class="class="post-thumb wp-post-image" style=' '> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </div><div class='cat-post-text'> <h1> <a href="<?php the_permalink(); ?>"><?php the_title(); ?>

 

First thing you should do is get a keyboard that that has return and tab keys. That will enable you to format your code into separate lines with indents so it is understandable.

When you've done that, repost your code using a code box ("<>" button in the toolbar).

If it's readable there's a chance someone might read it.

  • Like 1
2 minutes ago, Barand said:

First thing you should do is get a keyboard that that has return and tab keys. That will enable you to format your code into separate lines with indents so it is understandable.

When you've done that, repost your code using a code box ("<>" button in the toolbar).

If it's readable there's a chance someone might read it. Thanks for the guide. let me edit

 

<?php 
   query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num&
order=DESC');

    if (have_posts()) : while (have_posts()) : the_post();
?> 
<ul class="rpul">
    <li>    
        
            <?php endif ?> 
      
                <a href="<?php the_permalink(); ?>"><?php the_title();?>

Please I edited the code as directed. Anyone to help make this only most viewed post of 7 days? Thanks

You're not really showing us any code.  Just some calls to unique functions that we aren't aware of.   Show us an actual query statement that uses a where clause that would do this limit thing that you need.

 

As ginerjm stated we don't have any insight into how the function query_posts() works or what are the valid values to use.

query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC');

Does that function allow for parameters based on date ranges? Does it exclude records with 0 views? Even if it does, we have no idea how those parameters are to be formatted. But, generally speaking the query might look something like this:

SELECT *, COUNT(v.id) as viewCount
FROM posts_table as p
JOIN views_table as v
  ON p.id = v.post_id
  AND v.date >= DATE(NOW()) - INTERVAL 7 DAY
ORDER BY viewCount DESC

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.