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

Define category ID using get_post_meta

<?php global $wp_query; $cata = get_post_meta( get_the_ID(), ‘cata’, false); query_posts ( array( ‘cat’=> $cata, ‘showposts’ =>’1000′ ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!– BEER ITEM –> <div class=”menu-title”> <span><?php the_title(); ?></span> </div> <div class=”menu-desc-wrap”> <div class=”beer-discripton”> <span></span> <?php the_content(); ?> </div> <div class=”percent”><span> <?php echo get_post_meta( get_the_ID(), … Read more

Categories PHP Tags categories, custom-field, php, post-meta

Display post meta conditionally based on it’s value

If it’s created with ACF, then the way to call the field is like this: $can_download = get_field(‘enable_downloads’,$postid); so your code should look like: <?php global $wp_query; $postid = $wp_query->post->ID; $can_download = get_field(‘enable_downloads’,$postid); if ($can_download == ‘yes’) { ?> <?php } elseif ($can_download == ‘no’) { ?> <?php } elseif ($can_download == ‘other’) { ?> … Read more

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

Add a custom class to the body tag using custom fields

You want to use body_class filter. function prefix_add_body_class( $classes ) { global $post; // good to check if( ! is_single() || ‘post’ !== get_post_type() ) { return $classes; } $btag = get_post_meta( $post->ID, ‘tagbody’, true ); if ( empty( $btag ) ) { return $classes; } $classes[] = $btag; return $classes; } add_filter( ‘body_class’, ‘prefix_add_body_class’ … Read more

Categories PHP Tags custom-field, hooks, php, post-meta

How to call a post’s metadata in shortcode.php?

The first one doesn’t work because $post doesn’t exist inside the context of your shortcode function, you would need to add global $post; before it. However… You should use get_the_ID() instead of accessing the $post global directly. The reason it doesn’t work in your second example is that it’s not a class method, it’s just … Read more

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

Meta box data is saved but NOT displayed in the meta box text field. Why?

Try this.. function custom_meta_box_markup() { global $post; $meta_box_text = get_post_meta( $post->ID, ‘meta-box-text’, true ); ?> <div> <label for=”meta-box-text”>Day</label> <input name=”meta-box-text” type=”text” value=”<?php echo $meta_box_text;?>”> </div> <?php } You are missing the $post global variable which holds the post data.

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

How does WP decide how to display a page

WordPress has a predefined folder structure and runs on a database with a clearly defined structure. The description of the tables and the relationship between them is defined. You can store on the disk the plugins as well as the content that goes into /uploads, like you’ve mentioned. Yes, it should get rid of the … Read more

Categories posts Tags comment-meta, comments, post-meta, posts

Get audio metadata on file upload

Grab the data with a filter: add_filter(‘wp_update_attachment_metadata’, ‘grab_meta_data’); function grab_meta_data($data, $post_id) { // inspect $data here return $data; }

Categories plugin-development Tags loop, plugin-development, post-meta, uploads

Show number of posts by logged in user

Here a code example with explanation in the comments: // First a check whether the use is logged in or not: if ( is_user_logged_in() ) { // The user is logged, retrieve the user id $user_ID = get_current_user_id(); // Now we have got the user’s id, we can pass it to the function ‘count_user_posts’: echo … Read more

Categories posts Tags post-meta, posts, user-meta, users

How can I output WPAlchemy repeating fields meta values in my page template?

Per comments, here’s a (very rough) example of accessing repeated fields in the frontend. Note using WPAlchemy extract mode, which gives each field its own meta entry, and makes accessing them a bit simpler. Also using actions in “functions.php” to add metabox and to output content for test purposes – obviously you’d adapt the ‘init’ … Read more

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

Count of posts by different parameters?

Use WP_Query with a tax_query and a meta_query argument, and return only IDs to save a bit of server resource. $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘people’, ‘field’ => ‘slug’, ‘terms’ => ‘bob’, ), ), ‘meta_query’ => array( array( ‘key’ => ‘age’, ‘value’ => array( 3, 4 ), ‘compare’ … Read more

Categories custom-taxonomy Tags custom-taxonomy, post-meta
Older posts
Newer posts
← Previous Page1 … Page90 Page91 Page92 … 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