All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.

Author Topic: How to terminate query_posts(v_sortby=views&v_orderby=desc) ?  (Read 7366 times)

0 Members and 1 Guest are viewing this topic.

Offline leongsam

  • Newbie
  • *
  • Posts: 11
    • View Profile
Hey Lester, when I used query_posts(v_sortby=views&v_orderby=desc) for a particular query, all queries after will follow this sortby views. How do we terminate this function after a query so it doesn't run beyond the loop?

Thanks you in advance. Your plugin rocks.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
You may want to try:
Code: [Select]
wp_reset_query(); or better still use another loop

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline leongsam

  • Newbie
  • *
  • Posts: 11
    • View Profile
You may want to try:
Code: [Select]
wp_reset_query(); or better still use another loop
It doesn't work. It runs all over from loops to loops, from tables to tables, even from templates to templates especially when i used it in my header template. Any other ways to control it?
« Last Edit: 25 August 2008, 02:08 by leongsam »

Offline leongsam

  • Newbie
  • *
  • Posts: 11
    • View Profile
Hmm.. i read somewhere that generally query_posts('v_sortby=views&v_orderby=desc') would change the main query for the page and thus will change the results of whatever statements after. That is in my case.

What's funny is wp_reset_query() doesn't reset it to it's original state in my case.

That's really strange..

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
In that case why not use a different variable for example $recent_posts:
Code: [Select]
<?php 
$recent_posts 
= new WP_Query("showposts=10&what_to_show=posts&nopaging=0&post_status=publish");
while (
$recent_posts->have_posts()): 
$recent_posts->the_post();
?>

<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> - <?php the_time('jS F Y'); ?></li>
<?php 
endwhile; 
wp_reset_query();
?>

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline leongsam

  • Newbie
  • *
  • Posts: 11
    • View Profile
In that case why not use a different variable for example $recent_posts:
Code: [Select]
<?php 
$recent_posts 
= new WP_Query("showposts=10&what_to_show=posts&nopaging=0&post_status=publish");
while (
$recent_posts->have_posts()): 
$recent_posts->the_post();
?>

<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> - <?php the_time('jS F Y'); ?></li>
<?php 
endwhile; 
wp_reset_query();
?>


Hmm but the above code doesn't produces sort by views. What does nopaging=0&post_status=publish means? Also I think it's the resetting of the values of conditional properties in the default query object ($wp_query) and nothing I do after could set it back to it's original state which is sort by date whenever query_posts('v_sortby=views&v_orderby=desc') is called.

Because I had listed recent posts in my footer.php So whenever a page loaded that has the v_sortby=views, then the list of recent posts will turned to sorted by views instead, otherwise the footer.php is fine by itself.

I wonder could we call v_sortby=views&v_orderby=desc using WP_Query ?

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
That is just an example. You can can cal v_sortby=views&v_orderby=desc using WP_Query() as well.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline leongsam

  • Newbie
  • *
  • Posts: 11
    • View Profile
That is just an example. You can can cal v_sortby=views&v_orderby=desc using WP_Query() as well.

Nope. I tried to put in  v_sortby=views&v_orderby=desc in WP_query it returns something funny...oh well.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
I just tested it and apparently WP_Query() is not respecting the "v_sortby" and "v_orderby" arguments. Oh well, I guess if you may want to use the code which I posted a few posts up for the recent post code as that is what I am using on my website and then use query_posts() for sorting the views.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline leongsam

  • Newbie
  • *
  • Posts: 11
    • View Profile
I just tested it and apparently WP_Query() is not respecting the "v_sortby" and "v_orderby" arguments. Oh well, I guess if you may want to use the code which I posted a few posts up for the recent post code as that is what I am using on my website and then use query_posts() for sorting the views.

Nope, as long i execute v_sortby views, everything below that point will follow v_sortby views. It just doesn't terminate. Thanks for your help anyway.

Offline scorpio

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: How to terminate query_posts(v_sortby=views&v_orderby=desc) ?
« Reply #10 on: 23 February 2009, 11:36 »
i have the same issue now.
if any resolved ? thanks.

Offline enfermatiko

  • Newbie
  • *
  • Posts: 2
    • View Profile
I have a link on my site to the most viewed posts using (?v_sortby=views&v_orderby=desc) on the url and it shows the most viewed on the first loop and then 4 random posts on a second loop. I was able to terminate the sorting by views by using this after the first loop:

<?php remove_filter('posts_orderby', 'views_orderby'); ?>
<?php query_posts(array('orderby' => 'rand', 'showposts' => 4)); if (have_posts()) : while (have_posts()) : the_post(); ?>

but this only works when the second loop is called using "query_posts" and having multiple loops with "query_posts" gives me pagination problems. I need to call the loop using "wp_query" but <?php remove_filter('posts_orderby', 'views_orderby'); ?> doesn't work when the loop is called using wp_query. Any suggestions??


Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Don't use query_post(), create a new object of WP_Query instead. Refer to the 4th post in this thread.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline enfermatiko

  • Newbie
  • *
  • Posts: 2
    • View Profile
thanks, that's what I did and it worked!