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

String taken from database table post_meta is showing HTML tags on Frontend

Use the htmlspecialchars() function in PHP in the templates, because the wordpress-api does htmlspecialchars on import. The following code works fine <?php print htmlspecialchars_decode(get_post_meta($post->ID, ‘field_name’, true)); ?>

Categories post-meta Tags post-meta

wordpress custom loop ascending descending posts by custom field

If you would have created your own WP_Query, you could have done it this way: <?php $args = array( ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘price’ ); $new_query = new WP_Query( $args ); ?> See the examples in the docs: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters Since you are using the Mainloop, you need to act a bit … Read more

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

Get all the posts where meta field with multiple choice has several values checked

did you try to call like this: $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘spec’, ‘value’ => ‘choice2’, ‘compare’ => ‘LIKE’, ), array( ‘key’ => ‘spec’, ‘value’ => ‘choice3’, ‘compare’ => ‘LIKE’, ), ), ); $query = new WP_Query( $args ); example taken straigh from the codex

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

get_post_meta as a list for drop down search filter

First, you have a very basic PHP mistake: single quotes mean “string literal”. Variables won’t be processed. You are literally putting “$variable” into the generated code. Second, look at the third parameter of get_post_meta() $single (boolean) (optional) If set to true then the function will return a single result, as a string. If false, or … Read more

Categories metabox Tags meta-query, metabox, post-meta

Get $post->ID from a URL

I know that this is old question, but maybe this will help url_to_postid( string $url ) WP Code reference

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

WP_Query – Accessing MetaValue from Query Result

The WP_Query() only queries posts from the wp_posts table. Even if you add additional parameters such as: ‘meta_query’ => array( array( ‘key’ => ‘_thumbnail_id’ ‘compare’ => ‘EXISTS’ ) ) It looks at the wp_postmeta table to ensure that the posts it pulls has the post_meta _thumbnail_id but it does not also pull the post meta. … Read more

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

Get array of metakey in all posts

Your function is unreliable and totally overboard and really really expensive. Furthermore, as already stated by @MarkKaplun, you are not calling the_post() which causes the $post global not to be updated to the current post being looped through, so the value from get_post_meta() will always have the same value. Although $post_id might work, it is … Read more

Categories functions Tags array, functions, post-meta

Hide post title input for all roles except admin

I tried following code and its working. You need to place this in your theme’s funtions.php file. Let me know how it goes 🙂 add_action(‘admin_init’, ‘admin_only_post_title’); function admin_only_post_title() { if (!current_user_can(‘manage_options’)) remove_post_type_support(‘post’, ‘title’); }

Categories admin Tags actions, admin, customization, post-meta, title

Allow only one post with specific meta value

I want this condition to only be applied to one post, i.e. when the user declares a post as “featured”, and saves it, all the other ones (theoretically only the last one) that have this meta value checked, should be turned “off”. You might then try to save the one and only featured post ID … Read more

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

How to get posts with a metadata numeric key greater than X?

This kind of meta query in WP_Query() or get_posts(): ‘meta_query’ => [ [ ‘key’ => ‘score’, ‘value’ => 50, ‘type’ => ‘numeric’, ‘compare’ => ‘>=’, ], ], would generate the following SQL WHERE part: wp_postmeta.meta_key = ‘score’ AND CAST(wp_postmeta.meta_value AS SIGNED) >= ’50’ This kind of ordering: ‘orderby’ => [ ‘meta_value_num’ => ‘DESC’, ‘title’ => … Read more

Categories custom-field Tags custom-field, post-meta
Older posts
Newer posts
← Previous Page1 … Page110 Page111 Page112 … 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