I need to have a hidden custom field that will be automatically populated with the title of the post on save. My goal is to query posts by all its meta fields, including the title, but from my research I learned that it's not easily possible to combine title and meta_query.

What should be the script for creating this hidden field as meta?

2 Answers 2


This will automatically update a meta named post_title to the value of the post's title, no matter where you save the post from:

function wpse_275785_save_title_as_meta( $post_id, $post, $update ) {
    update_post_meta( $post_id, 'post_title', $post->post_title );
add_action( 'save_post', 'wpse_275785_save_title_as_meta', 99, 3 );

So you need hidden input field

<input type="hidden" name="yourName" value="yourValue"/>    

After hitting submit button you will put this code

update_post_meta( $post_id, 'yourMeta_key', 'yourMeta_value' );

And wordpress will put this info in postmeta table when you want this data

get_post_meta( $post_id, 'yourMeta_key' );


$productMeta = get_post_meta( $post_id );

EDIT to get your data from hidden field use

$_POST['yourName']; // yourName is name of hidden input field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.