• Hi!

    Just tried your plugin, and it seems to works great!

    I have one problem though. I have several blog categorieries, like this:

    – Main category 1
    \- Subcategory 1
    \- Subcategory 2

    – Main category 2
    \- Subcategory 1

    And so on. The “category_in” parameter only takes names of categories. If I enter “Subcategory 1” in this parameter, it will list all my categories called “Subcategory 1” for subscription. It would be better if you could pass in the ID of each category to list, to distinguish between similarly named categories.

    Better yet, a shortcode parameter to display the category and all its children would be great. Something like: [stc-subscribe hierarcy_from=”Main Category 1″].

    Thanks for an otherwise great plugin.

    https://www.ads-software.com/plugins/subscribe-to-category/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Stingray_454

    (@stingray_454)

    Did a quick patch on the current version, was easy enough to change:

    Changed the start of function html_render() in class-subscribe.php to

    public function html_render( $atts = false ){
    
          extract( shortcode_atts( array(
            'category_in' => false,
            'category_id_in' => false,
            'category_not_in' => false,
          ), $atts ));
    
          // add hook when we have a request to render html
      		add_action('wp_footer', array( $this, 'add_script_to_footer' ), 20);
    
          // getting all categories
          $args = array( 'hide_empty' => 0 );
      		$cats = get_categories( $args );
    
          if( !empty( $category_in ) ){
            $cats = $this->filter_categories_in( $cats, $category_in );
          }elseif( !empty( $category_id_in ) ){
            $cats = $this->filter_categories_id_in( $cats, $category_id_in );
          }elseif( !empty( $category_not_in ) ){
            $cats = $this->filter_categories_not_in( $cats, $category_not_in );
          }

    And added function

    /**
         * Filter to show categories by attribute 'category_id_in' in shortcode
         *
         * @param  array  $cats_all All categories
         * @param  string $cats_id_in  Categories entered in shortcode
         *
         * @since 1.3.0
         *
         * @return array            Array with categories to show
         */
        private function filter_categories_id_in( $cats_all = '', $cats_id_in = '' ){
    
          if(empty( $cats_all ))
            return false;
    
          $cats_id_in = explode(',', str_replace(', ', ',', $cats_id_in ) );
    
          $filtered_cats = array();
          foreach( $cats_id_in as $cat_id_in ){
            foreach ($cats_all as $cat ) {
              if( $cat_id_in == $cat->cat_ID )
                $filtered_cats[] = $cat;
            }
          }
    
          return $filtered_cats;
    
        }

    Works like a charm. Feel free to include something similar in the next release, as I’m not comfortable to used forked plugins on the site ??

    Plugin Contributor dansod

    (@dansod)

    Hi there!
    Many thanks for your suggestion and solution, i will definitly include it, at least as an option or as an attribut in shortcode.

    Thanks,
    Daniel

    Thread Starter Stingray_454

    (@stingray_454)

    The above code adds a “category_id_in” shortcode attribute, but if you have a better implementation idea I’m all for it.

    Thanks for a quick reply and happy to hear the requested feature is beeing added. Adding a 5-star review ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Give category_in with ID instead of name?’ is closed to new replies.