Support » Plugins and Hacks » TPG Get Posts » Boolean AND logic with TPG Get Posts

  • Resolved mmx0

    (@mmx0)


    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/

Viewing 1 replies (of 1 total)
  • Plugin Author cswaim

    (@cswaim)


    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.

Viewing 1 replies (of 1 total)
  • The topic ‘Boolean AND logic with TPG Get Posts’ is closed to new replies.