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 Meta Key Value While Saving Post

Think about what you’re doing here. You’re hooking into the time which WordPress is saving a post. You need to use get_post_meta() to check if the saving post has that required meta key. If you get nothing back, or get_post_meta() returns false, then you need to add your post meta for this saving post using … Read more

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

“update_post_meta” not working in “wp_insert_post_data” hook

Two issues with your code in current form: wp_insert_post_data hook runs before the actual insertion happens. In other words post might not not exist yet. Data in this hook does not contain post_id. More fitting hooks to use are those after post insertion is processed: do_action(‘save_post’, $post_ID, $post); do_action(‘wp_insert_post’, $post_ID, $post);

Categories post-meta Tags post-meta

Run a check for multiple meta key values

use php’s implode to join array elements with a string: <?php if( $bands = get_post_meta($post->ID, ‘band’) ): ?> <strong>Band:</strong> <?php echo implode( $bands, ‘, ‘ ); ?><br /> <?php endif; ?> EDIT- another version of above, pluralizing the label depending on single or multiple meta values: <?php if( $bands = get_post_meta($post->ID, ‘band’) ): $label = … Read more

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

is there a way to show the the post title after the image?

Look at: http://pastebin.com/2mKXyKa9 I’ve moved the content beneath the meta, so you have the order… 1. IMAGE 2. TITLE 3. META 4. CONTENT …as it currently stands, the partial snippet you pasted above has the content being called above the thumbnail. Also you are missed the block which contains the meta content, so it makes … Read more

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

How to implement a Google map store locator

I implemented a similar custom store locator for a client, and what I ended up doing was saving each lat / lon pair as post meta for a single location post type, and then assigning each location post type to a parent store post type. that way, a single store could have multiple unique locations. … Read more

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

How can I sort posts by the date and a custom meta field?

Basically, I am reading right out of the Codex page for WP_Query. You want a meta_query similar to this with an orderby parameter with the two values you want to order by. The first is dominant. $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( array( ‘key’ => ‘rating’, ‘value’ => 3, ‘compare’ => ‘>’ … Read more

Categories posts Tags custom-field, order, post-meta, posts, wp-query

Multiplicate entry on update_post_meta

<?php // Check to make sure array is ready if( isset($_POST[‘activite_dates’]) && is_array($_POST[‘activite_dates’]) ) { // If we have an array ready to save delete all the previous data delete_post_meta( $post_id, “dates”); foreach($_POST[‘activite_dates’] as $date) { // Use add post meta instead of passing the array directly in add_post_meta( $post_id, “dates”, esc_attr($date)); } } $dates_gf … Read more

Categories metabox Tags metabox, post-meta

How to add a new meta key and assign timestamp to posts

A very simplistic method of achieving this would be as follows; add_action(‘template_redirect’, ‘recently_read’); function recently_read(){ global $post; //only run this function for the posts post_type if ( !is_single() ) return; //get the current time in the format of: 2013-02-22 11:55:51 $timestamp = current_time(‘mysql’); //add the $timestamp variable to the meta_key for this post update_post_meta($post->ID, ‘reading_this’, … Read more

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

Update post meta on bulk edit / update

Try using the $post parameter: add_action( ‘pending_to_publish’, ‘sa_ads_count’ ); function sa_ads_count( $post ) { // use the $post variable here, not the missing global. }

Categories publish Tags bulk, post-meta, publish

filtering custom post types via meta data drop down

Because you want the results of the filtering process be the main object of your page, you may need to alter the main query using pre_get_posts action hook. It is really better that leave the main query run, load your theme and then say to WordPress: go back and run another query as suggested in … Read more

Categories custom-field Tags custom-field, filters, post-meta, search
Older posts
Newer posts
← Previous Page1 … Page141 Page142 Page143 … 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