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

Displaying Metabox value (custom post type taxonomy)

Try this For single template global $post; echo get_post_meta( $post->ID , ‘sm_taxonomy’, true ); OR For archive template if ( have_posts() ) : while ( have_posts() ) : the_post(); echo get_post_meta( get_the_ID() , ‘sm_taxonomy’, true ); endif;

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

How to make orderby ‘meta_value_num’ OPTIONAL?

Short answer: You can’t. Not like that, anyway. You could, however, grab all of the results from your query, regardless of the presence of that custom field, and completely unsorted, and then sort them using the PHP function uksort http://us1.php.net/manual/en/function.uksort.php Something like: $args = array( ‘cat’ => 5, ‘numberposts’ => 8 ); $posts = get_posts($args); … Read more

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

How to sanitize post meta field value?

HTML in custom fields is, from my point of view, a weird use case of custom fields. Even more if the purpose of the used HTML is just look and feel (<strong> and <i> can be seen as just look and feel). It is really better if you use the HTML markup on the custom … Read more

Categories post-meta Tags post-meta, sanitization

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
Older posts
Newer posts
← Previous Page1 … Page164 Page165 Page166 … Page203 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
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 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