Support » Fixing WordPress » Query individual custom post by title and retrieve meta

  • Ok, here’s one that’s had me stumped for days, hoping someone knows how to do this:

    I have multiple custom post types used for a job board. I’m dealing with a relationship between 2 custom post types JOB and TEAM MEMBER. Each job is assigned a team member which is called into a Select Box within a custom meta field in the JOB

    What I need to do now is within my contact_form.php file which is in the SINGLE JOB template, query the TEAM MEMBER custom post type by TITLE (the persons name is the title) and retrieve a meta field called OWNER…

    so basically:

    new wp_Query -> look in the custom post type ‘team’ for a post with the title of X team member and give me back the meta ‘owner’ for that post, then save it as a variable I can use outside this query

    Any ideas or direction would be GREATLY appreciated!

Viewing 1 replies (of 1 total)
  • Try something like this:

    $args = array(
    	'post_type' => 'team',
    	'name' => 'first-last'
    $the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();
          $owner = get_post_meta($post->ID, 'owner', true);

    BTW, here is a useful tool for generating query code:

Viewing 1 replies (of 1 total)
  • The topic ‘Query individual custom post by title and retrieve meta’ is closed to new replies.