• Miguel

    (@teledirigido)


    Would be perfect if we could select and customize amt_get_supported_post_types and choose the post_type to attach the metadata box.

    The plugin runs mean tho, pretty happy ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author George Notaras

    (@gnotaras)

    Hi. Thank you for your review.

    Actually, what you ask is possible. Please check the description page of the plugin. There is an example that contains sample code about how to customize the supported post types.

    Hint: there is also an undocumented filter amt_metabox_post_types which can be used to further customize on which post types a metabox is displayed in the post editing screen.

    Hope this helps! ??

    Plugin Author George Notaras

    (@gnotaras)

    If you need further info, start a new topic in the forum.

    Thread Starter Miguel

    (@teledirigido)

    Yeah!

    I added on amt_add_metadata_box a filter for $supported_type and is working pretty good. Thanks again.

    Cheers man!

    Plugin Author George Notaras

    (@gnotaras)

    Glad you made it work the way you want.

    Here are some more hints:

    The amt_supported_post_types filter (as shown in example 2 in the plugin homepage) can be used to control the post types Add-Meta-Tags generates metadata for. This also affects the post types on which the metabox is displayed. Perhaps this is where you should hook your filter function on.

    By default, the metabox is displayed on all supported post types except the attachments (for technical reasons).

    The undocumented filter amt_metabox_post_types exists only for extraordinary cases in which you want to hide the metabox for a post type, but still generate automatic metadata for it.

    Hope these help.

    George

    Thread Starter Miguel

    (@teledirigido)

    Wow! Cool good to know. I didn’t know about amt_metabox_post_types

    On functions.php I’ve added this:
    remove_action( 'add_meta_boxes', 'amt_add_metadata_box' );

    and then:
    add_action( 'add_meta_boxes', 'amt_add_metadata_box_custom_posts' );

    function amt_add_metadata_box_custom_posts() {
        $supported_types = amt_get_supported_post_types();
    
        // Add an Add-Meta-Tags meta box to all supported types
        foreach ($supported_types as $supported_type):
    
            // If post, page or new, then show the meta tags box.
            if ( $supported_type == 'post' || $supported_type == 'page' || $supported_type == 'new' ):
    
                add_meta_box(
                    'amt-metadata-box',
                    __( 'Metadata', 'add-meta-tags' ),
                    'amt_inner_metadata_box',
                    $supported_type,
                    'advanced',
                    'high'
                );
    
            endif;
    
        endforeach;
    
    }

    Hope this example could help someone ??

    Anyway I am gonna have a look on amt_metabox_post_types

    Thanks again George.

    Miguel

    Plugin Author George Notaras

    (@gnotaras)

    The plugin offers a simpler way to do this:

    function limit_metadata_to_post_types( $post_types ) {
        // here we do not use the provided $post_types, by return our custom array
        return array( 'post', 'book', 'project');
    }
    add_filter( 'amt_supported_post_types', 'limit_metadata_to_post_types', 10, 1 );

    By adding the code above to your functions.php you limit the generation of metadata (and consequently the addition of the metabox) to the following post types: post, book, project

    I think this is what you want and this is the simplest way to do it.

    George

    Plugin Author George Notaras

    (@gnotaras)

    Hey Miguel,

    I took a second look at your code, and I come to the conclusion that your case is one of those cases you need to use the undocumented filter amt_metabox_post_types.

    function limit_metabox_to_post_types( $post_types ) {
        return array( 'post', 'project');
    }
    add_filter( 'amt_metabox_post_types', 'limit_metabox_to_post_types', 10, 1 );

    By adding this to functions.php the metabox is only added to the edit screen of the types: post, project

    Metadata is still generated automatically for other post types, but no metabox is displayed for customization of that metadata.

    I hope these examples help you do what you want.

    George

    Thread Starter Miguel

    (@teledirigido)

    Cool man, this works perfect!

    Hope this will be useful for someone else ??

    Cheers

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Great plugin, pretty useful’ is closed to new replies.