Support » Plugin: Jetpack by WordPress.com » Appending some set hashtags to all post of specific post type

  • Resolved Craig

    (@digimouse)


    Hi,

    Is there a way through code to append some hashtags to the default message created from the title?

    I spotted a code snippet by Jeremy Herve below but because of the nature of the post type the cats used would not be appropriate:

    // Create our custom Publicize message
    function jeherve_cust_pub_message() {
    	$post = get_post();
    
    	// Grab the first category of your post
    	if ( !empty( $post ) )
    		$categories = get_the_category( $post->ID );
    
    	if ( !empty( $categories ) ) {
    		$previous_cust = get_post_meta( $post->ID, '_wpas_mess', true );
    
    		$custom_message = $categories[0]->cat_name . ' ' . $previous_cust;
    
    		update_post_meta( $post->ID, '_wpas_mess', $custom_message );
    	}
    }
    
    // Save that message
    function jeherve_cust_pub_message_save() {
    	add_action( 'save_post', 'jeherve_cust_pub_message', 21 );
    }
    add_action( 'publish_post', 'jeherve_cust_pub_message_save' );

    I would simply need to modify this to add a short string of hashtags if the post type is equal to job listing form wp job manager. However I have tried my hand and it and cannot get it to work.

    Hope you can help.

    https://wordpress.org/plugins/jetpack/

Viewing 1 replies (of 1 total)
  • Plugin Contributor Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    You can indeed start from that code snippet. You’d have to customize it so it returns early if the post type is not a WP Job Manager job listing (Post Type name is job_listing). You can check a post’s Post Type with get_post_type, like so: $post_type = get_post_type( $post->ID );

    I hope this helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Appending some set hashtags to all post of specific post type’ is closed to new replies.