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

Get Advanced Custom Fields values before saving [closed]

Edit – This answer is no longer accurate for the current version of ACF, see their documentation Use the acf_save_post hook. function my_acf_save_post( $post_id ) { // vars $fields = false; // load from post if( isset($_POST[‘fields’]) ) { $fields = $_POST[‘fields’]; } // … } // run before ACF saves the $_POST[‘fields’] data add_action(‘acf_save_post’, … Read more

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

I can’t set meta_key in my custom post type query

That’s because ‘meta_key’ and ‘meta_value’ are not public query vars. In other words, you can’t use them in URLs directly, nor should you. Instead, register a specific query var, like so: function register_my_qv() { global $wp; $wp->add_query_var( ‘my_qv’ ); } add_action( ‘init’, ‘register_my_qv’ ); Then, you can go to a URL like this: ?my_qv=foobar All … Read more

Categories custom-post-types Tags custom-post-type-archives, custom-post-types, meta-query, post-meta

Custom Post Type: Set post_title equal to a custom post type field

I would simply filter the_title so that it outputs the appropriate custom-field data for your custom post type: <?php function theme_slug_filter_the_title( $title ) { global $post; if ( ’employee’ == get_post_type( $post ) ) { $custom = ( get_post_custom( $post->ID ) ? get_post_custom( $post->ID ) : false ); $custom_title = ( isset( $custom[‘name’][0] ) ? … Read more

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

Save both current and new version of post meta

that could be caused by post revision being saved, and you should use wp_insert_post_data anytime you want to do something before the post is saved, here is an example plugin i just cooked up to test it and it looks like this: <?php /* Plugin Name: wpse37901 Plugin URI: http://en.bainternet.info Description: answer to http://wordpress.stackexchange.com/questions/37901/save-both-current-and-new-version-of-post-meta Version: … Read more

Categories post-meta Tags duplicates, post-meta

Query between two meta values?

Edited again to demonstrate adding and removing filters: Include these general functions in your functions.php. These are the filters you will invoke for the loops where you want to limit your query by these two meta values: function date_check_join( $join ) { global $wpdb; $join .= ” JOIN “.$wpdb->postmeta.” AS startdate ON (“.$wpdb->posts.”.ID = startdate.post_id … Read more

Categories post-meta Tags date-time, post-meta, sql

WP_Query not working as expected for attachments and custom meta_query

First, just pass your arguments to the constructor of WP_Query as this is both cleaner, and the way you’re supposed to do it according to the Codex documentation of the class. You should be constructing things like this: $my_key_query_args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘inherit’, ‘meta_query’ => array( array( ‘key’ => ‘my_key’, ‘value’ … Read more

Categories wp-query Tags meta-query, post-meta, wp-query

Front-end update_post_meta snippet displays white screen?

Change your nonce verify to actually verify and update post meta, else do nothing. But don’t use exit at the top of your template. // top of page if ( isset( $_POST[‘drw_inventory’] ) && wp_verify_nonce($_POST[‘drw_inventory’],’update_drw_postmeta’) ) { //if nonce check succeeds. global $post; $postid = $post->ID; $data = $_POST[‘priceone’]; update_post_meta($postid,’metakey’,$data); } // in single.php $priceone … Read more

Categories post-meta Tags post-meta

Check if meta key value already exists

Just do a query with WP_Query using the Custom Field parameters (meta_query) to look for posts with the meta key and the value – exemplary code: // args to query for your key $args = array( ‘post_type’ => ‘your_post_type’, ‘meta_query’ => array( array( ‘key’ => ‘videoid’, ‘value’ => $new_posts_videoid // for example: ‘111’ ) ), … Read more

Categories metabox Tags metabox, post-meta

Permalinks using event date (year & month) instead of publication date

The short answer: you need to modify the query for your single event post to include the metadata, so only posts with matching name, year, and month will be returned. I’ll show you the complete code I used to test this. I made a few changes to your code and simplified a few things, so … Read more

Categories custom-post-types Tags custom-post-types, date, permalinks, post-meta, rewrite-rules

How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?

When you save an array as post meta, WordPress will serialize it to a string and save that string. Let’s take a simple array: array ( 1 => array ( ‘url’ => “https://wordpress.stackexchange.com/”, ‘title’ => ‘Home’ ), 3 => array ( ‘url’ => ‘http://wordpress.stackexchange.com/’, ‘title’ => ‘WordPress Stack Exchange’ ), 4 => array ( ‘url’ … Read more

Categories post-meta Tags post-meta
Older posts
Newer posts
← Previous Page1 … Page184 Page185 Page186 … 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