• Resolved moonvader

    (@moonvader)


    What I want is to send only posts from selected categories to my telegram channel. How can I do it with this plugin?

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you know a little bit of coding in PHP, then add this code to functions.php in your active theme directory

    add_filter( 'wptelegram_filter_post', 'wptelegram_post_from_selected_categories' );
    function wptelegram_post_from_selected_categories( $post ) {
    
    	// get the categories associated with the post
    	$post_categories = wp_get_post_categories( $post->ID, array( 'fields' => 'id=>slug' ) );
    	
    	// array of category slugs to be allowed
    	$allowed_categories = array(
    		'cat1slug',
    		'somecatslug',
    		'cat2',
    	);
    
    	$send = false;
    
    	foreach ( $post_categories as $category ) {
    		// if the post category is in the allowed list
    		if ( in_array( $category, $allowed_categories ) ) {
    			$send = true;
    			break;
    		}
    	}
    	return $send;
    }

    Don’t forget to change the values in $allowed_categories array to the slugs of the categories you want to allow. You can also use category names in it, but then you need to change 'fields' => 'id=>slug' to 'fields' => 'names'
    If you do not know the coding, then you can email us at support@wptelegram.com, we can do it for you 🙂

    Thread Starter moonvader

    (@moonvader)

    First of all let me thank you for excellent and fast support!

    I also think that this feature with filtering not only by categories but also by authors – is needed widely. What about adding this ti plugin settings?
    For example I got this plugin only because I found out that it can have some kind of filtering on other’s wp telegram plugin support thread. I know how to edit PHP files of my theme but I definitely prefer this settings to be inside plugin settings tab.
    What do you think about it?

    Yes, it’s already in the upcoming features list to add those controls and much more to the settings page. Till then you can use the given filters 🙂
    You may mark this topic as resolved. Feel free to contact again.

    Thread Starter moonvader

    (@moonvader)

    So I’ll be waiting for this feature)!
    Wish you a great luck and thank you one more time!

    @moonvader,
    Please update the plugin and enjoy the features you wanted 🙂
    Consider writing a review if you like the features.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get post only from selected categories’ is closed to new replies.