Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Bainternet

    (@bainternet)

    //using a filter hook
    add_filter('USC_allowed_post_types','usc_filter_post_types');
    function usc_filter_post_types($types){
    	//add a custom post type
    	$types[] = 'MY_CUSTOM_POST_TYPE_NAME';
    	//remove a post type
    	if(($key = array_search('post', $types)) !== false) {
        	unset($types[$key]);
    	}
    }
    
    //or using action hook
    add_action('USC_add_meta_box','usc_add_metabox_to_ctp');
    function usc_add_metabox_to_ctp($obj){
    	add_meta_box(
    		'User_specific_content',
    		__( 'User specific content box'),
    		array($obj,'User_specific_content_box_inner'),
    		'MY_CUSTOM_POST_TYPE_NAME'
    	);
    }
    Thread Starter Anonymous User 13362967

    (@anonymized-13362967)

    Thanks ??

    This doesn’t work for custom post types. I just tried it for WooCommerce products. The field array shows up on the edit screen for products…but they are still visible to everyone. The listings in the store and the dedicated page for the product.

    Thoughts?

    I been looking for this all day. cant wait to try this out and see the results. Thanks Bainternet

    Sadly just test it the code and no luck, I have a custom post type, and the user specific content option dasn’t display.

    has anyone solve this?

    Thread Starter Anonymous User 13362967

    (@anonymized-13362967)

    It works for me

    Hey @iowjfowei can you please tell me where i may went wrong here.

    I understand I supposes to change the MY_CUSTOM_POST_TYPE_NAME
    to my custom post type slug name right..?

    example see the code below am using provided from @bainternet

    //using a filter hook
    add_filter('USC_allowed_post_types','usc_filter_post_types');
    function usc_filter_post_types($types){
    	//add a custom post type
    	$types[] = 'portfolio';
    	//remove a post type
    	if(($key = array_search('post', $types)) !== false) {
        	unset($types[$key]);
    	}
    }
    
    //or using action hook
    add_action('USC_add_meta_box','usc_add_metabox_to_ctp');
    function usc_add_metabox_to_ctp($obj){
    	add_meta_box(
    		'User_specific_content',
    		__( 'User specific content box'),
    		array($obj,'User_specific_content_box_inner'),
    		'portfolio'
    	);
    }
    Thread Starter Anonymous User 13362967

    (@anonymized-13362967)

    You use both codes? Use a filter hook or action hook, not both (I use second one) ??

    Hi @iowjfowei Thanks for getting back at me and no i tried the first code not a luck then i tried the second one still not a luck.

    All I want is to display the User Specific Content option on the custom post so i can apply that post for a specific user.

    Thanks. Work for me.

    Thanks for the code – I was able to get the action hook to work.

    How would you add it to multiple post types?

    Thanks!

    Jerrad

    X-Raym

    (@x-raym)

    I confirm the action hook works.

    Thank you so much!!

    Hi, I got this working, but could you please help me figure out how to use it on multiple custom post types? would it be like this:

    add_action('USC_add_meta_box','usc_add_metabox_to_ctp');
    function usc_add_metabox_to_ctp($obj){
    	add_meta_box(
    		'User_specific_content',
    		__( 'User specific content box'),
    		array($obj,'User_specific_content_box_inner'),
    		'portfolio' , 'movies' , 'reviews'
    	);
    }

    Solved the issue with the help of a different community:

    add_action('USC_add_meta_box','usc_add_metabox_to_ctp');
    
    function usc_add_metabox_to_ctp($obj){
    
        $post_types = array(
            'portfolio',
            'my_other_post_type',
            'page',
            'post' // etc
        ); 
    
        foreach ( $post_types as $post_type ) {
            add_meta_box(
                'User_specific_content',
                __( 'User specific content box'),
                array($obj,'User_specific_content_box_inner'),
                $post_type
            );
        }
    }
Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Add support to custom post type’ is closed to new replies.