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 7093327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:25:32+00:00 2026-05-28T08:25:32+00:00

So im trying to save a dropdown value in my custom post type. What

  • 0

So im trying to save a dropdown value in my custom post type. What am I doing wrong?

Markup:

<li><label>Location</label><input name="tf_events_location" value="<?php echo $meta_loc; ?>" /></li>
<li><label>Band relation</label>
    <select name="tf_events_relate" id="tf_events_relate">
      <option value="">All Artists </option>
      <option value="146">Mormor</option>
      <option value="140">John Face</option>
     </select>
</li>

And save

function save_tf_events(){

global $post;

if(!isset($_POST["tf_events_location"])):
    return $post;
    endif;
    $updateloc = $_POST["tf_events_location"];
    update_post_meta($post->ID, "tf_events_location", $updateloc);

if(!isset($_POST["tf_events_relate"])):
    return $post;
    endif;
    $updaterelate = $_POST["tf_events_relate"];
    update_post_meta($post->ID, "tf_events_relate", $updaterelate);
}

My tf_events_location gets saved allright, but my tf_events_relate is not doing anything.
I think i might be getting the principle wrong 😉

  • 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-05-28T08:25:32+00:00Added an answer on May 28, 2026 at 8:25 am

    The issue is that you are simply not telling the <select> element what <option> is selected when the page comes back.

    There are a number of different ways to do that, some more flexible than others, but in it’s most simple format with the html code you have above, this would work:

    <li><label>Location</label><input name="tf_events_location" value="<?php echo $meta_loc; ?>" /></li>
    <li><label>Band relation</label>
        <select name="tf_events_relate" id="tf_events_relate">
          <option <?php ($meta_relate == "") ? echo("selected "):; ?>value="">All Artists </option>
          <option <?php ($meta_relate == "146") ? echo("selected "):; ?>value="146">Mormor</option>
          <option <?php ($meta_relate == "140") ? echo("selected "):; ?>value="140">John Face</option>
         </select>
    </li>
    

    It isn’t the most elegant, but it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to save a custom object as a user setting in a
I am trying save the disabled property value of a hidden field to track
As the result of a form post, I'm trying to save a new Brand
Im trying to save a path into my input varaible, but its not reading
I'm trying save 3 entities, address, name and employee, with employee containing an address
Im trying to save a bitmap jpg format with a specified encoding quality. However
I am trying to save data to a database on a button push, but
I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms
I'm trying to save a PDF file to SQL Server and I already have
We are trying to save the state of the application on exit and restore

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.