最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is there possible way to modify custom post type?

programmeradmin1浏览0评论

I use a third party plugin and plugin has created a custom post type called "creations".

Bu there is no archive page, there is no single page, there is no admin menu page... But data are saving on database correctly.

Is there a possible way to the active admin menu, archive page & single page?

Other all behaviours of custom post type should be there like( Eg: if exclude_from_search is true, this shouldn't change)

I use a third party plugin and plugin has created a custom post type called "creations".

Bu there is no archive page, there is no single page, there is no admin menu page... But data are saving on database correctly.

Is there a possible way to the active admin menu, archive page & single page?

Other all behaviours of custom post type should be there like( Eg: if exclude_from_search is true, this shouldn't change)

Share Improve this question edited Jul 17, 2019 at 5:20 I am the Most Stupid Person asked Jul 10, 2019 at 5:46 I am the Most Stupid PersonI am the Most Stupid Person 5681 gold badge7 silver badges30 bronze badges 2
  • You can create templates for archive and single pages. For the admin page you have to examine the plugin for available hooks responsible for the admin page or ask the plugin developer. – Max Yudin Commented Jul 10, 2019 at 7:12
  • 1 You could use register_post_type_args or registered_post_type to modify the post type data. – Sally CJ Commented Jul 17, 2019 at 9:10
Add a comment  | 

2 Answers 2

Reset to default 12 +50

You can change register_post_type() arguments before the new type is created. To do this, use the register_post_type_args filter.

add_filter( 'register_post_type_args', 'se342540_change_post_type_args', 10, 2 );
function se342540_change_post_type_args( $args, $post_name )
{
    if ( $post_name != 'cpt_slug' )
        return $args;

    $args['has_archive'] = true;
    // 
    // other arguments

    return $args;
}

If the plugin only registers the CPT, remove it and build your own.

If the plugin does other things you need to keep on your site, you can unregister the post type and re-register it with your own plugin. You'll just need to keep in mind that changing settings may affect the way the original plugin works - it may rely on certain options in the CPT.

Either way, copy the part of the plugin that registers the CPT and then adjust just the options you need. Make sure to replace "post_type" below with the actual CPT name.

<?php
// Optionally unregister the post type to clear all settings
// (this does not delete any of the posts from the database)
unregister_post_type( 'post_type' );

// Now, re-register it as in the plugin, but with
// the adjusted settings you need
$args = array(
    // has_archive will provide an archive page
    'has_archive' => true,
    // 'supports' will enable an Editor for single pages
    'supports' => array('title', 'editor', 'author', 'revisions', 'page-attributes'),
    // 'public' makes it available in a number of places like menus
    'public' => true
);
register_post_type( 'post_type', $args );
?>
发布评论

评论列表(0)

  1. 暂无评论