admin管理员组

文章数量:1315325

I have created two custom post type. Suppose A and B.

I would like to fetch A custom post title in B in meta box in a drop-down.

I am not getting any solution.

Is anybody help me to find the solution.

Thanks in advance!!

I have created two custom post type. Suppose A and B.

I would like to fetch A custom post title in B in meta box in a drop-down.

I am not getting any solution.

Is anybody help me to find the solution.

Thanks in advance!!

Share Improve this question asked Nov 20, 2020 at 8:39 Neeraj PrasadNeeraj Prasad 13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You need to get all the titles of CPT (Custom Post Type) A, and loop through them in the second CPT in a metabox of CPT B. Example :

$my_titles = array(
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'order' => 'ASC',
    'post_type' => 'my_custom_post_type' // get the type of your CPT
);

Now in your second custom post type i.e B, inside the meta box loop through them like

    <select name="" id="">
        <?php foreach ($my_titles as $key => $title): ?>
            <option value=""><?php echo $title; ?></option>
        <?php endforeach ?>
    </select>

本文标签: plugin developmentShow a custom post title in another custom post type in Meta box