skip to Main Content

I am not sure how to use custom posts in WordPress. I have tried them with the plugin’s but, the problem here is when I have deactivated plugins which are not useful then the related posts are going down. I want to make them available. Is there any easy way to post them?

2

Answers


  1. You can add custom post type in WordPress by placing this in you theme functions file, you can also place this in must use plugin to for using it in all themes.

    function register_custom_post_type()
    {
        register_post_type(
            'team',
            array(
                'supports'      => array(
                    'title',
                    'editor',
                    'author',
                ),
                'taxonomies'          => array(
                    'category',
                ),
                'labels'      => array(
                    'name'          => __('Team', 'Our Team'),
                    'singular_name' => __('Team', 'Our Team'),
                    'menu_name'           => __('Team', 'Our Team'),
                    'all_items'           => __('All Team Members', 'Our Team'),
                    'view_item'           => __('View Team Member', 'Our Team'),
                    'add_new_item'        => __('Add New Member', 'Our Team'),
                    'add_new'             => __('Add New', 'Our Team'),
                    'edit_item'           => __('Edit Member', 'Our Team'),
                    'update_item'         => __('Update Member', 'Our Team'),
                    'search_items'        => __('Search Member', 'Our Team'),
                    'not_found'           => __('Not Found', 'Our Team'),
                    'not_found_in_trash'  => __('Not found in Trash', 'Our Team'),
                ),
                'public'      => true,
                'has_archive' => true,
    
            )
        );
    }
    add_action('init', 'register_custom_post_type');
    
    

    In view use the normal WordPress loop, just add this to your arguments,

    $args = array(
      'post_type'   => 'team',
      'post_status' => 'publish'
     );
     
    $team= new WP_Query( $args );
    
    
    Login or Signup to reply.
  2. The problem with using a plugin is that your custom post types will disappear when the plugin is deactivated. Any data you have in those custom post types will still be there ,but your custom type will be unregistered and will not be accessible from the admin area.

    You can use below code for the custom posts:

    $args = array( ‘post_type’ => ‘blog’, ‘post_per_page ’ => 10 ); $loop = new WP_Query(args ); While ( $loop-> have_posts() ): $loop->the_post(); the_title(); echo’<div class = ” entry-content “ >’; the_content(); echo’’; endwhile;

    Reference :

    https://www.wpbeginner.com/wp-tutorials/how-to-create-custom-post-types-in-wordpress/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search