• Hi,

    I’m using the WordPress Theme Daily, by theme junkie, and there is a widgetized ajax tabber that displays posts in the general sidebar.

    I want to use the ‘orderby=id&include’ function to call out specific posts to be displayed.

    Here is the stock code:

    // Tabber: Get Most Popular Posts
    function tj_tabs_popular( $posts = 5, $size = 48 ) {
    wp_reset_query();
    if(empty($posts)) $posts = 5;
    if(empty($size)) $size = 48;
    	$the_query = new WP_Query('caller_get_posts=1&showposts='. $posts .'&orderby=post_date&order=asc');
    	while ($the_query->have_posts()) : $the_query->the_post();
    ?>
    <li class="clear">
     	<?php
    				$thumb = get_thumbnail($post->ID, get_theme_mod('thumb_key'),get_theme_mod('thumb_key'));
    
    				if(!$thumb)
    					$thumb = get_bloginfo('template_url').'/images/default-thumb.gif';
    
    				$url = get_bloginfo('template_url').'/timthumb.php?src='.$thumb.'&h='.$size.'&w='.$size.'&a=t&zc=1';
    				echo '<a  class="entry-thumb"href="'.get_permalink().'" title=""><img width="'.$size.'" height="'.$size.'" src="'.$url.'" alt="" /></a>';
    			?>
     	<div class="info">
     	<a title="" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    	</div> <!--end .info-->
    </li>
    <?php endwhile;
    }

    When I change the line: $the_query = new WP_Query('caller_get_posts=1&showposts='. $posts .'&orderby=post_date&order=asc');

    to

    $the_query = new WP_Query('caller_get_posts=1&showposts='. $posts .'&orderby=id&include=603,654,657,714,724');

    nothing happens. It’s as if it doesn’t even read it, and it just keeps the old posts sorted by date in ascending order.

    Can anyone tell me what I’m doing wrong?

    Thanks!!!

Viewing 15 replies - 1 through 15 (of 25 total)
  • $orderby=ID

    note the capital ‘ID‘ not lowercase

    Thread Starter bc-int

    (@bc-int)

    Thanks for the reply, but it didn’t work still. I changed it to:

    $the_query = new WP_Query('caller_get_posts=1&showposts='. $posts .'$orderby=ID&include=603,654,657,714,724');

    …still nothing. Just ignores that code apparently and sorts by post date and ascending.

    ???

    lol oops, should be

    &orderby=ID

    typo :), my bad

    Thread Starter bc-int

    (@bc-int)

    Still doesn’t seem to work. It jumbles up the ascending order slightly, so that it looks like this:

    1)2nd newest
    2)newest
    3)3rd newest
    4)4th newest
    5)5th newest

    but it doesn’t show the posts that I want.

    ID #’s 603,654,657,714,724 are WAY older than the last 5 posts on my site. Thanks again though…any other ideas?

    try removing caller_get_posts=1& cause that forces stickies to appear before everything no matter what, and they’re always posted by date

    Thread Starter bc-int

    (@bc-int)

    Would I put something in place of that?

    Thread Starter bc-int

    (@bc-int)

    Took it out, so it reads:

    $the_query = new WP_Query('showposts='. $posts .'$orderby=ID&include=603,654,657,714,724');

    Still nothing…it’s funny that you said stickies are always posted by date, because the only function that will work, even with caller_get_posts=1& removed is post_date.

    Could there be something else in the code that’s forcing the stickies?

    You haven’t changed the $orderby, if you read it, it still shows $orderby, with the dollar sign it needs to be the ampersand &orderby

    $the_query = new WP_Query('showposts='. $posts .'&orderby=ID&include=603,654,657,714,724');

    should be the exact code

    Thread Starter bc-int

    (@bc-int)

    $the_query = new WP_Query('showposts='. $posts .'&orderby=ID&include=603,654,657,714,724');

    …and still nothing. I really appreciate your replies though. Do I have any other options?

    Yea, I write my queries in a more legible manner so this will look different, I also noticed that, the script might be using depreciated parameters depending on what version of WP you’re using. But lets try this, replace that whole $the_query stuff with:

    <?php
    $args = array();
    $args['posts_per_page'] = $posts;
    $args['post__in'] = array(603,654,657,714,724);
    $args['ignore_sticky_posts'] = 1;
    $args['orderby'] = 'ID';
    
    $the_query = new WP_Query($args);
    ?>

    depending on how you want your entries ordered you can put
    $args['order'] = 'ASC'; just below $args['orderby'] = 'ID'; DESC is the default so you won’t need to define it if that’s how you want the order.

    ** edited … make sure there are quotes around ID, forgot to add them in my first version of this post

    Thread Starter bc-int

    (@bc-int)

    // Tabber: Get Most Popular Posts
    function tj_tabs_popular( $posts = 5, $size = 48 ) {
    wp_reset_query();
    if(empty($posts)) $posts = 5;
    if(empty($size)) $size = 48;
    	$args = array();
    $args['posts_per_page'] = $posts;
    $args['post__in'] = array(603,654,657,714,724);
    $args['ignore_sticky_posts'] = 1;
    $args['orderby'] = 'ID';
    
    $the_query = new WP_Query($args);
    	while ($popular->have_posts()) : $popular->the_post();
    ?>
    <li class="clear">
     	<?php
    				$thumb = get_thumbnail($post->ID, get_theme_mod('thumb_key'),get_theme_mod('thumb_key'));
    
    				if(!$thumb)
    					$thumb = get_bloginfo('template_url').'/images/default-thumb.gif';
    
    				$url = get_bloginfo('template_url').'/timthumb.php?src='.$thumb.'&h='.$size.'&w='.$size.'&a=t&zc=1';
    				echo '<a  class="entry-thumb"href="'.get_permalink().'" title=""><img width="'.$size.'" height="'.$size.'" src="'.$url.'" alt="" /></a>';
    			?>
     	<div class="info">
     	<a title="" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    	</div> <!--end .info-->
    </li>
    <?php endwhile;
    }

    And I get “Fatal error: Call to a member function have_posts() on a non-object in public_html/wp-content/themes/daily/functions.php on line 401”

    Hmm…I know I must have made a syntax error somewhere?

    $the_query = new WP_Query($args); should be $popular = new WP_Query($args); I’m only assuming that’s line 401ish

    Looks like you changed this line:
    while ($popular->have_posts()) : $popular->the_post(); from using $the_query-> to using $popular->

    Thread Starter bc-int

    (@bc-int)

    WELL, it seems like we made some really good progress, lol. No errors or anything, but it only shows the post with ID 724 now, not the rest. Seems like it’s almost there! :)Thanks!

    Hrmmmm, I guess try setting the post_type after the orderby… lol, add

    $args['post_type'] = 'post';

    if you want posts or

    $args['post_type'] = 'page';

    if you want pages or if post doesn’t work … LoL

    Also if those IDs are a mixture of posts and pages you will have to do:

    $args['post_type'] = array('post','page');

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘How do I sort posts by page ID in this function?’ is closed to new replies.