0
votes

I am trying to learn how to build a dynamic Custom Post Types Plugin for Wordpress, I m using this old guide:

https://code.tutsplus.com/tutorials/building-a-dynamic-custom-post-type-plugin--wp-26322

but I cannot get it to work correctly, I was able to create the Dynamic Custom Post Types but every time I register a new Custom Post Type the Supports section with the 'title', 'editor', 'author', etc gets changed in the Custom Post Type that was created before.

(I found this plugin that was created using the same guide but it has the same erratic behavior.

This is the plugin: https://wordpress.org/plugins/dynamic-custom-post-type/)

To fully explain I am getting the Field editor, author, etc. or another field every time I add or edit another Custom Post Type even if the database says that for that Custom Post Type it should be off.

Any help would be appreciated.

3

3 Answers

1
votes

You need a good plugin. Try Custom Post Type UI plugin. There are lots of tutorial on this plugin too. Good luck!

1
votes

I actually wrote about a 4 step process for creating CPT content that doesn't require much coding:

1. Create Custom Post Types with code or plugin. Creating the CPT can either be done manually or using a plugin like CPT UI.

  1. Set custom fields for the CPT. We will show how this is done using ACF.

  2. Create demo content. In order to display the CPT content on your site, you need to add some demo content to your site.

  3. Embed the CPT content in your single and archive templates. Adding the dynamic content is done using Elementor’s Theme Builder templates.

Once you finish these steps, your custom post type content will be ready for publishing, and you can display it on any chosen CPT.

Browse through the whole post, including the video, and tell me what you think

https://elementor.com/wordpress-custom-post-types/

0
votes

Custom post type create just copy & paste below code in your theme function.php file:

add_action('init', 'wfd_team');

function wfd_team() {
    $labels = array(
        'name' => 'Member',
        'singular_name' => 'Member',
        'menu_name' => 'Teams',
        'name_admin_bar' => 'Team',
        'add_new' => 'Add New',
        'add_new_item' => 'Add New Member',
        'new_item' => 'New Member',
        'edit_item' => 'Edit Member',
        'view_item' => 'View Member',
        'all_items' => 'All Members',
        'search_items' => 'Search Members',
        'parent_item_colon' => 'Parent Members:',
        'not_found' => 'No Member found.',
        'not_found_in_trash' => 'No Member found in Trash.'
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'rewrite' => array('slug' => 'wfd-team'),
        'has_archive' => true,
        'menu_position' => 20,
        'menu_icon' => 'dashicons-groups',
        'supports' => array('title', 'editor', 'author', 'thumbnail')
    );
    register_post_type('wfd_team', $args);
}

Display custom post type in your post or page by shortcode, Add this code below your theme function.php & shortcode [wfd_team_short] paste your post or page.

function wfd_team_fun() {
    $query = new WP_Query(
            array('post_type' => 'wfd_team',
        'posts_per_page' => 3, 'post_status' => 'publish',
        'paged' => $paged, 'order' => 'DESC'
    ));

    if ($query->have_posts()) :
        ?>
        <?php while ($query->have_posts()) : $query->the_post(); ?> 
            <div class="col-sm-4">
                <div style="text-align: center;">
                    <?php
                    if (has_post_thumbnail()) {
                        the_post_thumbnail('medium_large');
                    }
                    ?>
                </div>
                <h2 style="text-align: center; font-weight: 700!important;"><?php the_title(); ?></h2>
                <p  style="text-align: justify;">
                    <?php
                    echo wp_trim_words(get_the_content(),30);
                    ?>
<a href="<?php the_permalink(); ?>">Read More</a>
                </p>
            </div>
            <?php
        endwhile;
        wp_reset_postdata();
        ?>
        <!-- show pagination here -->
    <?php else : ?>
        <!-- show 404 error here -->
    <?php endif; ?>


    <?php
}

add_shortcode('wfd_team_short', 'wfd_team_fun');