• Resolved anotherbreed

    (@anotherbreed)


    Hi,

    I have the following code that displays in a Page all the posts from a specific category. This category is specified in the Custom meta field of the post named ‘cateory’.

    I basicly need to extend this to display posts not from one category ID, but all categories excluding ‘Uncategorized’ that have ID 1.

    This is the code:

    <?php
    if (is_page() ) {
    $category = get_post_meta($posts[0]->ID, 'category', true);
    }
    if ($category) {
      $cat = get_cat_ID($category);
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      $post_per_page = 6; // -1 shows all posts
      $do_not_show_stickies = 1; // 0 to show stickies
      $args=array(
        'category__in' => array($cat),
        'orderby' => 'date',
        'order' => 'DESC',
        'paged' => $paged,
        'posts_per_page' => $post_per_page,
        'caller_get_posts' => $do_not_show_stickies
      );
      $temp = $wp_query;  // assign orginal query to temp variable for later use
      $wp_query = null;
      $wp_query = new WP_Query($args);
      if( have_posts() ) :
    		while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help to modify this code! (to display post from multiple categories)’ is closed to new replies.