WordPress.org

Ready to get started?Download WordPress

Forums

TPG Get Posts
[resolved] Boolean AND logic with TPG Get Posts (2 posts)

  1. mmx0
    Member
    Posted 1 year ago #

    Hi,
    I was looking for a plugin that would let me do boolean AND queries of post categories and I couldn't find one, but I was able to add two lines of code into the TPG get posts plugin and Boolean AND logic on categories works perfectly!

    This is TPG version 1.3.8.
    In tpg-get-posts/inc/tpg-gp-process.class.php I added this

    public function tpg_get_posts_gen($args = '') {
    		global $id, $post, $more, $more_link_text;
    
    		//default values passed to get_posts
    		$default_attr =
    		array(
    		  'numberposts'      => '100',
    		  'offset'           => '',
    		  'category'         => '',
    		  'category_name'    => '',
    		  'category__and'     => '', // <------------  added this line
    		  'tag'              => '',

    and then in the same file farther down, just above "//Setup params for query" comment I added:

    //added this statement
    		if ($r['category__and'] != '') $r['category__and'] = explode (",",$r['category__and']);
    		// End added stuff
    
    		//setup parms for query

    Then in the short code you just use:
    [tpg_get_posts category__and=50,22,3,5] // NOTE: IT'S TWO UNDERSCOREs!!
    and it works wonders!

    MMX

    http://wordpress.org/extend/plugins/tpg-get-posts/

  2. cswaim
    Member
    Plugin Author

    Posted 1 year ago #

    The 2.0 version implements this functionality, though not exactly the same way. It also supports category__in and category__not_in. Plus enhanced formatting options. If you don't want to upgrade, this patch works. Thanks for posting for all to use.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic