Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    That’s not possible at the moment, but that’s an option we’d like to add to Jetpack in the future.
    You can follow our progress about this here:
    https://github.com/Automattic/jetpack/issues/7

    I’ll also post here as soon as I have some news!

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Hi,

    I just wanted to come back to this thread, with some good news! As of the next major Jetpack release, 4.1, you’ll be able to exclude some posts from Publicize thanks to the publicize_should_publicize_published_post filter.

    Here is how you could use it:

    /**
     * Do not trigger Publicize if the post uses the <code>private</code> tag.
     */
    function jeherve_control_publicize( $should_publicize, $post ) {
        // Return early if we don't have a post yet (it hasn't been saved as a draft)
        if ( ! $post ) {
            return $should_publicize;
        }
    
        // Get list of tags for our post.
        $tags = wp_get_post_tags( $post->ID );
    
        // Loop though all tags, and return false if the tag's name is <code>private</code>
        foreach ( $tags as $tag ) {
            if ( 'private' == $tag->name ) {
                return false;
            }
        }
    
        return $should_publicize;
    }
    add_filter( 'publicize_should_publicize_published_post', 'jeherve_control_publicize', 10, 2 );

    Hello! this is GREAT news! I have 4 categories and i want 1 category to never be published, so are you saying that i just add the code about to the bottom of functions.php – which part to i have to alter to define the category ID?

    thank you very much.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    @angad1 The example I posted above uses tags to control Publicize, not categories.

    If you’d rather use categories instead, you’ll need to look for categories in the post, instead of using wp_get_post_tags.

    Hello Jeremy, sorry i didnt meant to use the word published.

    Hello! this is GREAT news! I have 4 categories and i want 1 category to never be publicized, so are you saying that i just add the code about to the bottom of functions.php – which part to i have to alter to define the category?

    Could you give an example as to how i could exclude a category from publicizing?

    thank you.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Something like this will do the trick:

    /**
     * Do not trigger Publicize if the post uses the <code>private</code> category.
     */
    function jeherve_control_publicize( $should_publicize, $post ) {
    	// Return early if we don't have a post yet (it hasn't been saved as a draft)
    	if ( ! $post ) {
    		return $should_publicize;
    	}
    
    	if ( in_category( 'private', $post->ID ) ) {
    		return false;
    	}
    
        return $should_publicize;
    }
    add_filter( 'publicize_should_publicize_published_post', 'jeherve_control_publicize', 10, 2 );

    However, please note, as I mentioned before, that will only be available in the next major Jetpack release, Jetpack 4.1. ??

    Thank you Jeremy – appreciate that update! great work! ??

    hello,
    could you give an example because I don’t see how to make it I Want that publisize publish categorie1 and categorie2 but not categorie3
    Where I should make concretely categorie1 and categorie2 on the code ?

    /**
    * Do not trigger Publicize if the post uses the private category.
    */
    function jeherve_control_publicize( $should_publicize, $post ) {
    // Return early if we don’t have a post yet (it hasn’t been saved as a draft)
    if ( ! $post ) {
    return $should_publicize;
    }

    if ( in_category( ‘private’, $post->ID ) ) {
    return false;
    }

    return $should_publicize;
    }
    add_filter( ‘publicize_should_publicize_published_post’, ‘jeherve_control_publicize’, 10, 2 );

    I would like something like this but this is probably not working
    /**
    * Do not trigger Publicize if the post don’t uses one of the categorie .
    */
    function jeherve_control_publicize( $should_publicize, $post ) {
    // Return early if we don’t have a post yet (it hasn’t been saved as a draft)
    if ( ! $post ) {
    return $should_publicize;
    }

    $categories = array( ‘assurance’, ‘commerce’, ‘internet’, ‘comptabilite’, ‘credit’, ‘developpement-personnel’, ‘articles-finance’, ‘les-arnaques’, ‘articles-les-bons-plans’, ‘articles-investissements’, ‘bourse’, ‘patrimoine’, ‘crowfunding’, ‘fiscalite’, ‘immobilier’, ‘produits-bancaires’, ‘livres’, ‘articles-economie’,’entreprises’,’societe’, ‘tests-avis-des-plateformes-de-crowdfunding’, ‘annuaire-crowdfunding’);
    return $categories;
    }
    return $should_publicize;

    if not return false
    }
    }

    return $should_publicize;
    }
    add_filter( ‘publicize_should_publicize_published_post’, ‘jeherve_control_publicize’, 10, 2 );

    Thread Starter Bryan Cady

    (@bobcatou)

    Might have to use category ids instead? Not sure

    i don’t know i m not able to program anything

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Could you try something like this? It seems to work in my tests:

    /**
     * Do not trigger Publicize if the post uses the <code>private</code> category.
     */
    function jeherve_control_publicize( $should_publicize, $post ) {
        // Return early if we don't have a post yet (it hasn't been saved as a draft)
        if ( ! $post ) {
            return $should_publicize;
        }
    
        // Get list of categories for our post.
        $categories = get_the_category( $post->ID );
    
        // Loop though all categories, and return false if the category's name is <code>private</code>
        foreach ( $categories as $category ) {
            if ( 'private' == $category->name ) {
                return false;
            }
        }
    
        return $should_publicize;
    }
    add_filter( 'publicize_should_publicize_published_post', 'jeherve_control_publicize', 10, 2 );

    Tahnk you but it doesn’t help me, i don’t know where to make the category I need prety sure to make something in you code like this but i don’t know where (i’m not able to code anything ):

    probably somewhere here if I understand:
    // Loop though all categories, and return false if the category’s name is private
    foreach ( $categories as $category ) {
    if ( ‘private’ == $category->name ) {
    return false;
    }
    }

    ‘assurance’, ‘commerce’, ‘internet’, ‘comptabilite’, ‘credit’, ‘developpement-personnel’, ‘articles-finance’, ‘les-arnaques’, ‘articles-les-bons-plans’, ‘articles-investissements’, ‘bourse’, ‘patrimoine’, ‘crowfunding’, ‘fiscalite’, ‘immobilier’, ‘produits-bancaires’, ‘livres’, ‘articles-economie’,’entreprises’,’societe’, ‘tests-avis-des-plateformes-de-crowdfunding’, ‘annuaire-crowdfunding’

    sorry

    and thank you

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Just to be clear, you’d like Publicize to be triggered for all categories, except for the ones you listed above?

    Thread Starter Bryan Cady

    (@bobcatou)

    I’m following this thread and want to do the same thing and exclude certain categories. Wouldn’t it be better to use the category ids to mark exclusions?

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Can Publicize publish only certain categories?’ is closed to new replies.