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

How to display meta box data using “Meta boxes as needed”

You might wish to try; <?php $mykey_values = get_post_custom_values(‘my_key’); foreach ( $mykey_values as $key => $value ) { echo “$key => $value (‘my_key’)<br />”; } ?> Where my_key would be equal to songs. Another example of what I might do in a situation where I am dealing with multiple values; <?php global $post; $meta = … Read more

Categories metabox Tags metabox, post-meta

Random meta field from specific custom post type

You could pull it directly form the database: global $wpdb; $random_photo = $wpdb->get_var(“SELECT meta_value FROM wp_postmeta WHERE meta_key like ‘single_photo’ ORDER BY RAND()”);

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

Post AND page parameter for WP function

There’s no reason you can’t call add_meta_box() twice in a row and use the same function to display it both times; just change the $post_type parameter. Example foreach ( array ( ‘post’, ‘page’ ) as $post_type ) { add_meta_box( ‘your_id’, ‘your title’, ‘your_callback’, $post_type ); }

Categories custom-post-types Tags custom-post-types, functions, metabox, parameter, post-meta

Create action running on trashed_post hook to modify post_meta value

wp_trash_post and trashed_post – from source: function wp_trash_post($post_id = 0) { if ( !EMPTY_TRASH_DAYS ) return wp_delete_post($post_id, true); if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; if ( $post[‘post_status’] == ‘trash’ ) return false; do_action(‘wp_trash_post’, $post_id); add_post_meta($post_id,’_wp_trash_meta_status’, $post[‘post_status’]); add_post_meta($post_id,’_wp_trash_meta_time’, time()); $post[‘post_status’] = ‘trash’; wp_insert_post($post); wp_trash_post_comments($post_id); do_action(‘trashed_post’, $post_id); return $post; }

Categories custom-post-types Tags actions, custom-post-types, hooks, post-meta, trash

Show related (archive) month and year to post

Use following code after the loop: $month_num = get_the_date(‘n’); $month_txt = get_the_date(‘F’); $year = get_the_date(‘Y’); // change ‘posts_per_page’ to any value you need, ‘-1’ means ‘all’ query_posts( ‘posts_per_page=-1&monthnum=’.$month_num.’&year=”.$year ); echo “<p class=””>Archived in ‘.$month_txt.’, ‘.$year.'</p>’; echo ‘<ul>’; while ( have_posts() ) : the_post(); echo ‘<li><a href=”‘.get_permalink().'”>’.get_the_title().'</a></li>’; endwhile; echo ‘</ul>’; wp_reset_query(); It’s not tested, but you … Read more

Categories posts Tags post-meta, posts

Saving Revision of post meta key/value on each update_post_meta event

You’d need to set up an additional custom field and update it whenever the user changes or updates the original custom field.

Categories date Tags date, post-meta, revisions

How to update post meta with xml data

On which hook of WP init this code part? $user_id – why and from how is this var value? update_post_meta() will use the post ID, see Codex.

Categories post-meta Tags post-meta, xml

WordPress Attachments vs Post Meta

The WordPress “gallery” functionality partly depends on the attachment of the media to the post via the post_parent column. Specifying IDs in your shortcode allows you to include images in your gallery that aren’t necessarily “attached” to your post — that is to say, not uploaded from within your post or page. This flexibility allows … Read more

Categories attachments Tags attachments, post-meta

Querying meta values within an array

Answering my own question, as suggested in my edit I’ve had to use the following meta_query array to query the posts: ‘meta_query’ => array( array( ‘key’ => ‘country’, ‘compare’ => ‘LIKE’, ‘value’ => ‘”‘ . get_the_ID() . ‘”‘ ) )

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

fetch meta fields inside a widget

I fixed this by adding: global $post; More specific: I can’t explain why this works, that’s beyond my WordPress skills, but I added it right after the start of the query, so the code looks like this: <?php global $post; $loop = new WP_Query( array( ‘post_type’ => ‘kurs’, ‘posts_per_page’ => ‘5’, ‘meta_key’ => ‘dato’, ‘meta_value’ … Read more

Categories custom-post-types Tags custom-post-types, post-meta, widgets
Older posts
Newer posts
← Previous Page1 … Page16 Page17 Page18 … 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