The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. mmx0
    Posted 3 years ago #

    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 =
    		  '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!



  2. cswaim
    Plugin Author

    Posted 3 years 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

  • TPG Get Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic