• Hi,
    I want to display links below each post on the startpage. Based on a list of IDs for each post. Now I use custom queries and the $get_res = wpdb->get_results($querystr, ARRAY_A)

    I found it more easy to work with, but is it very bad to do it this way rather than a get_posts and the post__in, performance wise?

    I found a discussion about it where some argued wp_super_cache wouldnt perform as well when using custom queries.

    the custom query is a simple one

    $querystring = SELECT p.ID, p.post_title, date_format(p.post_date, '%d/%c') as formatted_date
        FROM $wpdb->posts p
        WHERE p.ID IN ($the_ID_list)
    	AND p.post_status = 'publish'
    	AND p.post_type = 'post'
        ORDER BY p.post_date DESC
Viewing 1 replies (of 1 total)
  • <?php
    //$the_ID_list = '476,419,72';
    $args=array(
      'post__in' => explode("," , $the_ID_list),
      'orderby' => 'date',
      'order' => 'DESC',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
Viewing 1 replies (of 1 total)

The topic ‘Which query to use’ is closed to new replies.