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

Branch made by several custom values

Use in_array(), like this: $search = [ ‘AAA’, ‘BBB’, ‘CCC’, ‘DDD’ ]; $meta = get_post_meta( $post->ID, ‘MY_CUSTOM_KEY_A’, true ); if ( in_array( $meta, $search ) ) { update_post_meta( $post->ID, ‘MY_CUSTOM_KEY_B’, ‘ZZZ’ ); }

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

Ajax: Populate with content from a post’s ID not working – duplicating current page html instead

First, you made a really, really silly typo: ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ….. url: funnel_ajax.ajax_url, ajaxurl != ajax_url. So your Admin AJAX request is not returning a full HTML page. You’re not even hitting the AJAX file! However, this is still completely the wrong way to go about this I was going to suggest … Read more

Categories plugin-development Tags ajax, jquery, plugin-development, post-meta, theme-development

Change post author without using wp_update_post()

On the few occasions when I’ve needed to do something similar, I’ve used the callback unattach-update-reattach method, which is also described on this older Q&A, Update post on save and on the developer docs comments. function your_save_post_callback( $post_id, $post, $update ) { // unattach the callback remove_action(‘save_post’, ‘your_save_post_callback’); // update post wp_update_post( $args ); // … Read more

Categories posts Tags author, post-meta, posts, save-post

How to detect that the save_post hook is calling the callback associated to the current edit post page only

Any function hooked to the save_post hook will run whenever you save a post. That is expected behaviour. You should use the hook save_post_{$post->post_type} to specify to which post type that callback is asociated. That way, it will only be called when saving a post of type {$post->post_type} See the hook documentation

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

How to modify the output of wp_terms_checklist when used within the built-in category metabox on edit posts?

Yes, as the documentation for wp_terms_checklist() stated, you can use the walker argument (which is part of the $args parameter for the wp_terms_checklist_args hook) to use a custom walker which modifies the output of the Category checklist generated by wp_terms_checklist(), e.g. the one in the “Categories” meta box on wp-admin/post.php. Example where the custom walker … Read more

Categories categories Tags categories, metabox, post-meta, taxonomy, walker

WP API Response does not show my registered metadata

For posts (Posts, Pages and custom post types), the very first parameter for register_meta() is always post and to set a custom post type, use the object_subtype argument in the third parameter like so: $meta_args = array( ‘object_subtype’ => ‘splash_location’, // the post type ‘type’ => ‘string’, ‘description’ => ‘A meta key associated with a … Read more

Categories custom-post-types Tags custom-post-types, post-meta, rest-api

“Cannot use import statement outside a module” JS error while adding a custom meta block?

You should use @wordpress/scripts so you can profit from modern JavaScript language features and JSX and transpile it to browser-compatible code. It’s really not complicated to use. Just install it via npm install @wordpress/scripts –save and than you can transpile your source file like this wp-scripts build src/myguten.js.js –output–path=js. It’s not only modern language features … Read more

Categories post-meta Tags block-editor, post-meta

WP nonce field checkbox prints checked=’checked’ outside input field

This is because you have used the checked() function, which echoes its value, inside another echo statement. If you are adding a value to a string you need the function to return a value. This can be done by setting the third argument, $echo, to false: echo ‘<lable for=”zoom_activity_state”> <input type=”checkbox” name=”zoom_activity_state” value=”‘ . $zoom_activity_state … Read more

Categories plugin-development Tags metabox, plugin-development, post-meta

How to fill custom fields with brackets in their key with add_post_meta()?

This is the PHP serialization format, and is used to serialize arrays for storage in the database. Core WordPress functions take care of this process for you. You just need to use an array as the value. For example, this: $schema_article = array( ‘headline’ => ‘aaa’, ); update_post_meta( $remote_id, ‘_schema_article’, $schema_article ); Will save this … Read more

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

How to use two meta_compare in an array?

Ok so this way is a bit long but it will get the job done. We can use multiple meta_value checks with AND relation // get posts $posts = get_posts(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 150, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘usp-custom-1’, ‘value’ => ‘question’, ‘compare’ => ‘!=’, ), array( ‘key’ … Read more

Categories PHP Tags array, php, post-meta
Older posts
Newer posts
← Previous Page1 … Page102 Page103 Page104 … 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