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

delete_post_meta() for whole CPT / multiple posts?

The Core lacks a function for that kind of bulk delete, so far as I know. The safest thing to do is to Loop over the posts in your CPT and delete the fields. $del = array( ‘list’, ‘of’, ‘keys’, ‘to’, ‘delete’ ); $args = array( ‘post_type’ => ‘book’, ‘posts_per_page’ => -1, ‘ignore_sticky_posts’ => true, … Read more

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

Difficultly changing date format in post meta value

Oh my. You’re doing some freaky stuff there. 🙂 Please try it like this: $args = array( ‘posts_per_page’ => -1, ‘post_type’=> ‘match_report’, ); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $matchdate = get_post_meta(get_the_ID(), ‘report_date’, true); $new_matchdate = DateTime::createFromFormat(‘d-m-Y’, $matchdate); update_post_meta(get_the_ID(), ‘report_date’, $new_matchdate->format(‘Y-m-d’)); } wp_reset_postdata(); } // EDIT If you have problems … Read more

Categories post-meta Tags post-meta

Filter posts by tax (dropdown) and meta value

To do the taxonomy query in your case, the code would be like this: if (isset($_POST[‘cat’]) && !empty($_POST[‘cat’])){ $args[‘tax_query’] = array( array( ‘taxonomy’ => ‘roadkill_category’, ‘field’ => ‘id’, // or slug ‘terms’ => $_POST[‘cat’], ‘operator’ => ‘IN’ ) ); } If you have further questions about tax query, please refer to the Codex.

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

Issue on Working with Metabox – Checkbox to enable Sale Items

You should focus on getting it to save first. There are endless amount of tutorials online on how to do it, but I would recommend using a plugin called Advanced Custom Fields. That let’s you create custom fields in specific pages/posts, without writing any code. This plugin also provides you with functions to use on … Read more

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

How to Echo Metadata Value in Currency Format

WordPress core has number_format_i18n() function, which allows to set number of decimal digits and apploes appropriate formatting in line with site’s locale. However note that it is not specific to money and there can be more peculiar requirements to handle such.

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

Setting Post Title via Meta Data returns Auto-draft

As soon as you hit “Add New” and the new post pages starts to load, WordPress inserts a mostly blank post template into the database. Periodically after that you get auto-saves. You don’t want either. You will need to add additional conditions to prevent your code from running in those circumstances. Something like this in … Read more

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

value of metadata is null wrong use of if statement

Try: $rating = get_post_meta($post->ID, ‘ratings_score’, false); var_dump($rating); You will notice that you get an array, even if your ratings_score is 2. To wit: array(1) { [0]=> string(1) “2” } That will never equal 2 so your condition will never work. The third parameter of get_post_meta() if set to true will collapse that array to a … Read more

Categories loop Tags loop, post-meta

bulk update meta value with ajax

After click on <a> tage send an ajax request. I will write only php code do jQuery part yourself. <script type=”text/javascript” > jQuery(document).ready(function($) { var data = { action: ‘my_action’ }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php $.post(ajaxurl, data, function(response) { //Do watever after you get … Read more

Categories ajax Tags ajax, post-meta

Create Array from custom post type to display a slider

You are using the_post_thumbnail() which will echo the actual thumbnail. You should use get_the_post_thumbnail() if you want the value to be returned, not echoed. So, change: $slide_img = the_post_thumbnail(); To: $slide_img = get_the_post_thumbnail(); You should also, as Matt points out, make sure you are using the correct meta field names and check if the values … Read more

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

User function to return multiple get_post_meta()

The second and third argument to get_post_meta() are optional. If not provided– ie. get_post_meta($post->ID)— you will get an array of all meta for the post. If only $id is set it will return all meta values in an associative array. http://codex.wordpress.org/Function_Reference/get_post_meta#Return_Value For example: $meta = get_post_meta($post->ID); var_dump($meta);

Categories functions Tags functions, post-meta
Older posts
Newer posts
← Previous Page1 … Page108 Page109 Page110 … 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