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

How to include template according to meta post value

Finally got a solution. I was not able to get meta key ie my_key value then I used: $post_id = get_the_ID(); $has_customization = get_post_meta($post_id, ‘my_key’, true);

Categories templates Tags include, post-meta, templates

get_post_meta doesn’t work

You got the wrong id for your get_post_meta(). As you define the input-name by the id of the field in your metabox, it has to be portfolio_description. <?php echo get_post_meta($post->ID, “portfolio_description”, true); ?> Should do the trick. If you are not sure which name of the post_meta you need to call, try inspecting the input … Read more

Categories metabox Tags metabox, post-meta

update_post_meta from data in multidimensional array created from a form

First off, there’s a problem with your array. Arrays can not have duplicate keys. So, only the first key will be saved. You need to change your form to something like this. <input name=”mainStageSatOrder[theband0][theid]” type=”hidden” class=”band-id” value=”” />”; <input name=”mainStageSatOrder[theband0][theorder]” type=”hidden” class=”band-order” value=”” />”; <input name=”mainStageSatOrder[theband1][theid]” type=”hidden” class=”band-id” value=”” />”; <input name=”mainStageSatOrder[theband1][theorder]” type=”hidden” class=”band-order” value=”” … Read more

Categories array Tags array, post-meta

How to solve slow WordPress site caused by attachment_metadata

Rick James and I have created the (free, GPL) Index WP MySQL for Speed plugin. It addresses some of the performance problems with wp_postmeta by adding database indexes suitable for that table’s use cases. I use it myself on a Woo site with several thousand products. (It works on users, terms, options, and comments too.) … Read more

Categories Database Tags database, mysql, optimization, performance, post-meta

Rest Api v2 orderby meta_key in custom post type

You can use this filter to change order : $type = “cptCode”; add_filter(“rest_” . $type . “_query”, function ($args, $query) { $args[“orderby”] = “meta_value”; $args[“meta_key”] = “my_meta_field”; return $args; }, 10, 2); You can also test $_GET to change the order conditionally.

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

Display info from custom fields in all images’ HTML

You can create a filter using the “wp_get_attachment_image_attributes” hook. Place this in your functions.php file. function filter_image_title($attr, $attachment = null){ //Find your $photographer with $attachment->ID $attr[‘title’] .= ‘ (‘ . __(‘Photographed by’, ‘foobar’) . ‘ ‘ . $photographer . ‘)’; return $attr; } add_filter(‘wp_get_attachment_image_attributes’, ‘filter_image_title’, 10, 2);

Categories custom-field Tags attachments, custom-field, hooks, images, post-meta

Edit meta data does’t work with custom sql

Try the following… global $wpdb; $wpdb->query( ” UPDATE {$wpdb->prefix}postmeta SET post_id = {$edit_id}, meta_key = ‘{$meta_key}’, meta_value=”{$meta_value}” WHERE post_id = {$edit_id} AND meta_key = ‘{$meta_key}’ ” ); //or using prepare $wpdb->query( $wpdb->prepare( ” UPDATE {$wpdb->prefix}postmeta SET post_id = %d, meta_key = %s, meta_value = %s WHERE post_id = %d AND meta_key = %s “, $edit_id, … Read more

Categories posts Tags post-meta, posts

Create custom field on post draft or publish?

Add an array and choose one for the value. add_action(‘draft_post’, ‘add_custom_field’); function add_custom_field($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { $colors = array(‘white’, ‘green’, ‘blue’); add_post_meta($post_ID, ‘random_color’, $colors[array_rand($colors, 1)], true); } }

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

How should I use posts_where to change meta_value from a string to integer?

Try this: add_filter(‘posts_where’, ‘unquote_numeric_meta_value’, 10, 2); function unquote_numeric_meta_value($where, $args) { $value = isset($args->query_vars[‘meta_value’]) ? $args->query_vars[‘meta_value’] : false; if(is_numeric($value)) $where = str_replace(“‘{$value}'”, $value, $where); return $where; }

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

do_shortcode based on _thumbnail_id

// function to show a banner using query of banner post type function show_banner( $att ) { // Set default $att values if none is provided // $att is an array so access the shortcode value via $att[‘thumbnail_id’] // in the [banner thumbnail_id=”12″] shortcode $atts = shortcode_atts( array( ‘thumbnail_id’ => ”, ), $atts, ‘banner’ ); … Read more

Categories shortcode Tags database, post-meta, shortcode
Older posts
Newer posts
← Previous Page1 … Page180 Page181 Page182 … 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