Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:11:27+00:00 2026-06-17T09:11:27+00:00

I have successfully pulled a custom post type through into a drop-down that is

  • 0

I have successfully pulled a custom post type through into a drop-down that is in a custom meta box. However, when displaying it on the front end I would like to also provide a link to the actual post, not just the name of the post. So I am guessing I need to save this as an array? Is this possible through a drop-down? Confused on how I should approach this. Any help is greatly appreciated.

Here is what I have so far:

// Add Meta Box To Select Overseeing Pastor
add_action('admin_init', 'ministry_select_add_meta');
function ministry_select_add_meta(){
    add_meta_box('ministry_select_post', __('Overseeing Pastor'), 'ministry_select_meta', 'ministry', 'side');
}

function ministry_select_meta( $post ) {
    $values = get_post_custom( $post->ID );
    $selected = isset( $values['pastor_select'] ) ? esc_attr( $values['pastor_select'][0] ) : '';
    wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
    ?>
        <select name="pastor_select">
            <?php
            $args = array(
                'post_type' => 'employee',
                'position' => 'pastor'
            );
            $pastorList = new WP_Query($args); while ($pastorList->have_posts()) : $pastorList->the_post();
                $is_selected = (get_the_title() == $selected) ? 'selected="selected"' : '';
                echo '<option value="'.get_the_title().'" '.$is_selected.'>'.get_the_title().'</option>';
            endwhile; wp_reset_postdata();
            ?>
        </select>
    <?php   
}

add_action( 'save_post', 'ministry_select_save' );
function ministry_select_save( $post_id )
{
    // Stop If Autosaving
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    // Stop If Nonce Can't Be Verified
    if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;

    // Stop If Unauthorized User
    if( !current_user_can( 'edit_post' ) ) return;

    // Make Sure Data Is Set Then Save      
    if( isset( $_POST['pastor_select'] ) )
        update_post_meta( $post_id, 'pastor_select', esc_attr( $_POST['pastor_select'] ) );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:11:28+00:00Added an answer on June 17, 2026 at 9:11 am

    So I came up with a different solution. Instead of trying to save an array, I just saved the post ID which would allow me access to the title of the post as well as the permalink.

    This is my modified code

    <select name="pastor_select">
        <?php
        $args = array(
            'post_type' => 'employee',
            'position' => 'pastor'
        );
        $pastorList = new WP_Query($args); while ($pastorList->have_posts()) : $pastorList->the_post();
            $employeeID = get_the_ID(); // THIS FIXED THE PROBLEM
            $is_selected = ($employeeID == $selected) ? 'selected="selected"' : '';
            echo '<option value="'.$employeeID.'" '.$is_selected.'>'.get_the_title().'</option>';
        endwhile; wp_reset_postdata();
        ?>
    </select>
    

    And this is how I am calling it on the front end

    <?php 
    $id = $post_meta_data['pastor_select'][0];
    echo '<a href="'.get_permalink($id).'">';
    echo get_the_title($id);
    echo '</a>';
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully created a feature in sharepoint that modifies the existing edit dialog
I have successfully created a custom Facebook open graph action, and have been able
I have successfully installed Eclipse and the Android SDK on Fedora 16. However, when
I have successfully made a custom control-slider, but it's not draggable. I tried searching
I have successfully uploaded files into my SQL Server database. I can bring back
I have successfully set up a quick test of creating a REST-like service that
I have successfully used protobuf-net.dll in console and WPF applications. However, when I tried
I have successfully installed FOSUserBundle in my project and everything works as expected. However,
I have successfully implemented a Csv Media Type Formatter in my ASP.Net Web API
I have successfully managed to create Visual Studio starter kits in the past, however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.