Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

post-meta

use post meta in add_meta_boxes action

You can not put condition in callback function as it will display the meta box without the HTML. Better you can wrap add_meta_box() in if condition. If you are on post edit screen you can get the post id in this way. $post_id = false; if (!empty($_POST[‘post_ID’])) { $post_id = $_POST[‘post_ID’]; } else if (!empty($_GET[‘post’])) … Read more

Categories metabox Tags metabox, post-meta

Custom post type term names with ampersand in the term name

Custom post type term names with ampersand in the term name

Categories custom-taxonomy Tags custom-taxonomy, post-meta, terms

update_post_meta not working in function

Figured it out. I had to re-read the codex a lot to figure out that when you pass an array to update_post_meta it is serialized. By using maybe_unserialize() on the return value I was able to to get access to the values. Hope this helps some future searcher!

Categories functions Tags advanced-custom-fields, custom-field, functions, post-meta

Save values generated via API as custom meta fields

Use the wp_insert_post hook to run when a post is saved: function wpse_188435_save_movie_data( $post_id ) { if ( $imdb = get_field( ‘imdb_id’, $post_id ) ) { if ( $imdbInfo = get_imdb_connector_movie( $imdb ) ) { if ( isset( $imdbInfo[‘actors’] ) ) update_post_meta( $post_id, ‘actors’, $imdbInfo[‘actors’] ); if ( isset( $imdbInfo[‘languages’] ) ) update_post_meta( $post_id, ‘languages’, … Read more

Categories custom-field Tags custom-field, post-meta

How to add post reference field to a plugin?

You can create something similar to WYSIWYG link dialog by generating traditional HTML SELECT with OPTIONs as post items, and then make it more interactive (searchable,…) with Chosen jQuery library. It’s not as precise solution as that in editor, but it can be enough for you.

Categories custom-post-types Tags custom-field, custom-post-types, post-meta

Disable Facebook Comments Automatically On CPT

I ended up going with this type of solution. It seems to be working fine for me. I am open on ways to improve this code as it seems there is a better hook that could be used. function on_music_publish( $post_ID, $post ) { if ( $post->post_type != ‘music’ ) { return; } update_post_meta($post_ID, ‘_disable_fbc’, … Read more

Categories custom-post-types Tags custom-post-types, post-meta, publish

Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]

Looking at the function update_woocommerce_term_meta(), you would recognize it just uses the wordpress function update_metadata(), which essentially means that woocommerce is using meta values, just like you do in you CPT. With this in mind, I wouldn’t think this procedure would slow down your site + your keeping compatibility by using existing functions. Also 20 … Read more

Categories custom-post-types Tags custom-post-types, custom-taxonomy, post-meta, woocommerce-offtopic

Display Data From This Custom Media Upload Meta Box?

you have to use “esc_attr” in case your value contains a quote for exemple <?php echo esc_attr(get_post_meta(…));?>

Categories custom-field Tags custom-field, metabox, post-meta

WP_Query Posts by Metadata from Option Tree

You might be missing the ‘meta_key’ arg here: $args = array( ‘ignore_sticky_posts’=> 1, ‘meta_key’ => ‘wpl_location’, // here ‘post_type’ => ‘post_projects’, ‘meta_query’ => array( array( ‘key’ => ‘wpl_location’, ‘value’ => ‘Europe’, ‘compare’ => ‘IN’, ), ), ); source: https://codex.wordpress.org/Class_Reference/WP_Query (about three quarters down the page).

Categories wp-query Tags meta-query, plugin-option-tree, post-meta, wp-query

Storing post_meta fields in array

I agree with kraftner’s comments to the question. This is a bad idea and you stand a good chance of regretting it later. Store you data as granular post meta values. Everything is easier later on. However, add_post_meta() and save_post_meta() will serialize objects/arrays for you. You don’t have to do anything special: update_post_meta(1,’my_bad_idea’,array(‘i’,’will’,’regret’,’this’,’later’)); And get_post_meta() … Read more

Categories post-meta Tags post-meta
Older posts
Newer posts
← Previous Page1 … Page33 Page34 Page35 … Page204 Next →
+ More

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
Next Page »
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress