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 conditionally after save post

Well, first use the hook properly. The post ID will be passed in. You don’t need $post->ID. Second, use the correct hook. If you want to run save_post only for your booking type, use save_post_booking But otherwise, the code works. I just ran a quick test. function booking_status_is_updated($post_id){ if(get_post_meta($post_id,’booking_status’,true)==’denied’){ delete_post_meta($post_id,’booking_slot’); } } add_action(‘save_post_booking’,’booking_status_is_updated’);

Categories post-meta Tags post-meta, save-post

Custom field value based on other custom field values

I recommend you look into the get_{$meta_type}_metadata filter. This is a basic hook setup to return a dynamic post meta value: <?php add_filter( “get_post_metadata”, function( $points, $post_id, $meta_key, $single ){ if ( ‘points’ == $meta_key && $single ) { update_post_meta( $post_id, ‘rank’, calculate_post_rank( $post_id, $points ) ); } return $points; }, 10, 4 );

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

Displaying custom posts only if custom meta box’s date is not expired

In your loop while(have_posts() ) : the_post(); you are unconditionally going through all posts, but since the loop stops after the_post() nothing actually happens. So that’s where the condition has to go: while(have_posts() ) { the_post(); if ($daysleft >= 0) { … other actions } } Your code looks a bit incomplete to me, so … Read more

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

Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]

Ok, so here’s the right answer, with the full code for an ACF Repeater Field: $count = get_post_meta( get_the_ID(), ‘items’, true ); if ( $count ) { for ( $i = 0; $i < $count; $i++ ) { $item_100x100 = intval( get_post_meta( get_the_ID(), ‘items_’ . $i . ‘_item_100x100’, true ) ); $item_200x200 = intval( get_post_meta( … Read more

Categories custom-field Tags advanced-custom-fields, custom-field, genesis-theme-framework, post-meta

Meta tags in shortcode

Since evasmat_posted_on() is a function in your theme, you don’t need to use get_post_meta to get the date. You can call the function directly so: function evasmat_posts_shortcode(){ $q = new WP_Query( array( ‘orderby’ => ‘date’, ‘posts_per_page’ => ‘4’) ); $list=”<div class=”cards”>”; while($q->have_posts()) : $q->the_post(); $list .= ‘<div class=”card”>’ . get_the_post_thumbnail() . ‘<h2 class=”entry-title-index”><a href=”‘.get_permalink().'”>’.get_the_title() .'</a></h2>’ … Read more

Categories shortcode Tags post-meta, shortcode

Why is variable value emptry in $_POST but available in $_REQUEST?

Using $_REQUEST is a bad practice. Between post requests, get requests, and cookies you can not be certain that you are processing actual user input and not some garbage left in the URL or in the browser’s memory. Meta boxes are “posted” so use only $_POST when processing them. The other aspect of your code … Read more

Categories metabox Tags metabox, post-meta

WordPress widget new instance creates content duplicates

I don’t see anything wrong with the widget class. The problem you have is that you are displaying the widget area, that contains the widgets, twice in your sidebar.php: <aside id=”secondary” class=”widget-area col-sm-12 col-md-12 col-lg-12″ role=”complementary”> <div class=”col-lg-6 col-md-12″> <?php dynamic_sidebar( ‘main-widget’ ); // this will display all the widgets in your main-widget sidebar ?> … Read more

Categories widgets Tags mysql, post-meta, register-sidebar, sidebar, widgets

How can I get values using key in Carbon Fields from Multiselect?

One of the Carbon Fields developers here. Thank you for your feedback! Currently, the Carbon Fields stores only the keys and they don’t have a built-in method to retrieve the selected values from the options array. You can pass a callable which returns an array with the options as an argument to the add_options method. … Read more

Categories post-meta Tags post-meta

Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta

Here’s an answer to question 1 that uses register_post_meta. It’s also the start of an answer to question 2 by use of the prepare_callback option in show_in_rest . add_action( ‘init’, ‘wpse_89033_register_custom_meta’ ); function wpse_89033_register_custom_meta() { $post_types = [ ‘post’, ‘page’, ‘attachment’, ]; foreach ( $post_types as $post_type ) { register_post_meta( $post_type, ‘_custom_key’, array( ‘type’ => … Read more

Categories custom-field Tags block-editor, custom-field, post-meta, rest-api

Explanation for remove_filter used in the below code [closed]

The remove_filter() is necessary to avoid the callback from being called recursively, which would result in a memory issue due to a never-ending function execution. And that recursion could happen because the callback is hooked to get_post_metadata which is invoked via the get_metadata() function which the callback calls. So you need to first “unhook”/unregister the … Read more

Categories filters Tags actions, filters, post-meta
Older posts
Newer posts
← Previous Page1 … Page166 Page167 Page168 … 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