Articles of custom field

How to Validate Post Meta type/extension (Video File Image File etc)

I am trying to learn meta’s in WordPress by taking an example of the already existing meta → function cpmb_display_meta_box( $post ) { // Define the nonce for security purposes wp_nonce_field( plugin_basename( __FILE__ ), ‘cpmb-nonce-field’ ); // Start the HTML string so that all other strings can be concatenated $html = ”; // If the […]

MySQL query to set wp_postmeta using term_taxonomy_id value

I have a need to set the wp_postmeta value (in table: wp_postmeta) on every post that has a specific term_taxonomy_id (in table: wp_term_relationships): Specifically: run a query against every post_ID that has term_taxonomy_id value of 18 if the wp_postmeta for that post_ID doesn’t contain the key of _category_permalink_ then add it with the value set […]

Save custom user meta on registration

I’m trying to create my own registration form and adding phone number as required field and I would love to save that phone number as custom user meta. After validation and santizing inputs, ets. my code looks like this: // this returns the correct value etc. – string(9) “126777889” var_dump($metas[‘user_phone’]) $user_id = wp_insert_user($fields); add_user_meta( $user_id, […]

Adding a Nav menu to post admin

i want insert a dropdown menu with list of menus, that i’ve created in nav-menu.php, to post-admin… For example, when i’m creating a post, i want insert a menu “Paul” in a post (only a post that i want) selecting a menu at right sidebar of Admin-Post. I’ve copied the rows: add_action( ‘init’, ‘register_my_menus’ ); […]

Determine when a custom field was last updated?

Would anyone know of a way to determine when a custom field for a post was last updated? I’m trying to write something that says “If CUSTOMFIELD was updated in the last 24 hours don’t do anything, else update it” but don’t see any time stamps in the database for this. Any clever ideas floating […]

Security checking in meta_box save is reluctant?

For example, in this tutorial, the code suggested when saving meta box data is /* Verify the nonce before proceeding. */ if ( !isset( $_POST[‘smashing_post_class_nonce’] ) || !wp_verify_nonce( $_POST[‘smashing_post_class_nonce’], basename( __FILE__ ) ) ) return $post_id; /* Get the post type object. */ $post_type = get_post_type_object( $post->post_type ); /* Check if the current user has […]

How to get custom field image url of specific size

I have a “cmb2” custom field with type->file. and i use it to upload images. If i use: echo get_post_meta( $post->ID, ‘_pf_photo1’, ‘medium’ ); i get the url of the full image (not the medium one). How can i get the url of the ‘medium’ / ‘thumbnail’ and so on…

Separate table or usermeta

We are creating custom fields for users like annual income, gender, city, country, etc. There are about 10 odd new fields. We will be importing approx. 30,000 records for each user in a month through a CSV import function. There will be new as well as update to old records. The process will continue for […]

custom field to always to .get_the_title()?

Is there a way to have always the the_title() tag also includes a custom field called subtitle? I want to have a title like this: “subtitle-custom-field: Post Title“. For example, “Cool: The new TV show from Werner Herzog.” In this case, cool would be the custom field value, and the new TV… would be the_title(). […]

How to get a meta value from all post

I searched for a while but I didn’t find any solution. I used the functions listed here. It outputs something like this: Array ( [0] => 15 [1] => 30 [2] => 50 ) But I want something like this: Array ( [post_id_1] => 15 [post_id_2] => 30 [post_id_3] => 50 ) And this is […]