Forums

[Plugin: List category posts] List posts with Two categories (8 posts)

  1. ABCDiamond
    Member
    Posted 2 years ago #

    Is it possible to create a catlist that only shows posts that are included in two specific categories.

    eg: Instead of [catlist id=18,19 orderby=title order=asc numberposts=-1 Date=no] which shows all posts from either Category 18 or 19, I would like something that only shows posts that are in BOTH category 18 AND 19, maybe something like [catlist id=18+19...

    End result being that if a post is only in either 18 or 19 it will not be shown, but posts that are in both 18 and 19 will be shown.

    http://wordpress.org/extend/plugins/list-category-posts/

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    If the plugin doesn't do that, then get PHP Exec plugin and put something like this in your post/page

    <?php
    $args=array(
      'category__and' => array(18,19),
      '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() ) {
      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().
    ?>
  3. drexp2000
    Member
    Posted 2 years ago #

    I am interested on the solution for this issue as well

  4. zawiw
    Member
    Posted 1 year ago #

    I would also be grateful if their would be a solution for this problem in list-category-posts

  5. zawiw
    Member
    Posted 1 year ago #

    I added a solution for this to list_cat_posts.php

    Replace Line 62:
    $category = 'cat=' . $atts['id'];

    by:

    if (strpos($atts['id'],'+')){
    	$category = explode('+',$atts['id']);
    	$category_criteria = 'category__and';
    }else{
    	$category = explode(',',$atts['id']);
    	$category_criteria = 'category';
    }

    And replace Line 75:

    $catposts = get_posts($category.'&numberposts=' . $atts['numberposts'] .
    				'&orderby=' . $atts['orderby'] .
    				'&order=' . $atts['order'] .
    				'&exclude=' . $atts['excludeposts'] .
    				'&tag=' . $atts['tags'] .
    				'&offset=' . $atts['offset'] );

    by:

    $catposts = get_posts(array(
    				$category_criteria => $category,
    				'numberposts' => $atts['numberposts'],
    				'orderby' => $atts['orderby'],
    				'order' => $atts['order'],
    				'exclude' => $atts['excludeposts'],
    				'tag' => $atts['tags'],
    				'offset' => $atts['offset'] ));

    Hope this helps and finds its way into the official plugin version

  6. ABCDiamond
    Member
    Posted 1 year ago #

    MichaelH

    Thanks for the reply, I didn't see it until today, not sure why ! oops.

    It works though :) But not sure I like that PHP Exec plugin. I saved it twice, and the 2nd save stuffed the code. But doing it again fixed it.

    I would like to see the original plugin have that facility, as it is easier to use. But then... whatever works in the long run :)

    Now I need to work out how to get other bits showing, eg: excerpts, or even special TDOMF custom fields, but this may be getting too technical.

    Thanks for what you did, and sorry for not seeing it, and replying earlier.

  7. ABCDiamond
    Member
    Posted 1 year ago #

    zawiw

    I tried your idea, but it stuffed up and didn't show any page with catlist on, after the heading. Not sure if I did something wrong or not.

    If you did get it to work, I would love to see your entire list_cat_posts.php to see where I went wrong.

    Thanks.

  8. Jay Collier
    Member
    Posted 1 year ago #

    Bump +1.

    Integrating this feature would make this great plug-in even better!

Topic Closed

This topic has been closed to new replies.

About this Topic