YSGmesh Posted September 4, 2019 Share Posted September 4, 2019 <?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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/309180-i-am-trying-to-modify-this-code-to-show-only-most-viewed-post-in-7-days-instead-of-all-time/ Share on other sites More sharing options...
Barand Posted September 4, 2019 Share Posted September 4, 2019 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309180-i-am-trying-to-modify-this-code-to-show-only-most-viewed-post-in-7-days-instead-of-all-time/#findComment-1569382 Share on other sites More sharing options...
YSGmesh Posted September 4, 2019 Author Share Posted September 4, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309180-i-am-trying-to-modify-this-code-to-show-only-most-viewed-post-in-7-days-instead-of-all-time/#findComment-1569384 Share on other sites More sharing options...
YSGmesh Posted September 4, 2019 Author Share Posted September 4, 2019 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/309180-i-am-trying-to-modify-this-code-to-show-only-most-viewed-post-in-7-days-instead-of-all-time/#findComment-1569385 Share on other sites More sharing options...
ginerjm Posted September 4, 2019 Share Posted September 4, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309180-i-am-trying-to-modify-this-code-to-show-only-most-viewed-post-in-7-days-instead-of-all-time/#findComment-1569390 Share on other sites More sharing options...
Psycho Posted September 4, 2019 Share Posted September 4, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309180-i-am-trying-to-modify-this-code-to-show-only-most-viewed-post-in-7-days-instead-of-all-time/#findComment-1569392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.