Is there some way to provide the user a list of existing content in a CPT

I was looking at the way WordPress uses “Or Link to Existing Content” under the link button in the editor and I am wondering if there is any way I can use that code to allow users to select a page to link to when they create a new custom post.

The context I am talking about is that of slides for a slider linking to content within the site.

Related posts

Leave a Reply

1 comment

  1. I’ve run across this before. What I did was use get_posts() to return a list of the pages in the site and making the pages options in a drop down menu in a meta box.

    // $your_args is an array that you've previously declared to get all the pages.
    $pages = get_posts($your_args);
    
    foreach( $pages as $page ) :
    ?>
    <option value="<?php echo $page->ID; ?>"><?php echo $page->post_name; ?></option>
    <?php
    endforeach;
    

    When you save the post, it will save the page’s ID in the custom post’s post meta.