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

Adding new value to existing meta key

Use the following instead of add_post_meta: update_post_meta($post_id, ‘when’ $date); add_post_meta does just that, adds a new meta key every time, including duplicates in your case. update_post_meta also incorporates add_post_meta if a key doesn’t exist, but updates an existing key. For reference: http://codex.wordpress.org/Function_Reference/update_post_meta If you want to store rolling dates in an array, you would simply … Read more

Categories post-meta Tags post-meta

Read post meta values, only if posts are public

Yes, do an INNER JOIN, something like this should work: $values = $wpdb->get_col($wpdb->prepare(” SELECT meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE meta_key= %s AND {$wpdb->posts}.post_status=”publish”” ,$metakey )); I changed $wpdb->get_results() to $wpdb->get_col() since it looks like you are just selecting a single column of data as an array. I also added $wpdb->prepare() … Read more

Categories post-meta Tags post-meta, select, wpdb

get_post_meta not extracting title,permalink and posttype

Post metas are used for storing custom data that you want to store and retrieve yourself. The default post data post type, title, permalink are not saved in post meta. You can retrieve post_type and title using get_post() function which returns a WP_Post object. For permalink you need to use get_permalink() function like this. $post … Read more

Categories post-meta Tags post-meta

cleaning up safely wordpress wp_postmeta table

The only generic semi-automatic procedure I can think of would be to delete post meta where the post_id is invalid. SELECT * FROM {$wpdb->postmeta} as pm LEFT JOIN {$wpdb->posts} as p ON pm.post_id = p.ID WHERE p.ID IS NULL I wrote a SELECT and not a DELETE because I don’t trust that to work in … Read more

Categories post-meta Tags customization, optimization, post-meta, sql

Trying to get property of non-object error using get_post_meta()

$post is never set on init when I test this– function topSub( $Trunckvalue = null ) { global $post; var_dump($post); } add_action( ‘init’, ‘topSub’ ); The earliest hook I can find (by experimentation, not a canonical statement) is wp. Aditionally, $post is set on archive pages as well as “single” pages. On those archive pages … Read more

Categories post-meta Tags post-meta

Custom query, multiple custom keys

I’m not an SQL expert, but I would think you might have to JOIN twice to pick two distinct rows out of wp_postmeta: $featuredquery = ” SELECT wposts.* FROM $wpdb->posts wposts JOIN $wpdb->postmeta article_level ON ( wposts.ID = article_level.post_id AND article_level.meta_key = ‘article_level’ ) JOIN $wpdb->postmeta article_genre ON ( wposts.ID = article_genre.post_id AND article_genre.meta_key = … Read more

Categories post-meta Tags customization, post-meta, query-string

Is it possible to retrieve a post and its metadata at the same time?

It’s not a single step, but it’s easy to write & handle in code: get_post_custom() gives you all attached meta data. But be aware: Everything comes as array, even when it´s a single value. So // Ever entry comes like this. // Example single value for ‘Hair color’: Array( [0] => Array( ‘Brown’ ) )

Categories post-meta Tags get-posts, post-meta

get_post_meta is showing file url in url bar

You should check the urls in your Custom field. This function adding http for invalid url. function addhttp($url) { if (!preg_match(“~^(?:f|ht)tps?://~i”, $url)) { $url = “http://” . $url; } return $url; } And finally: <?php function addhttp($url) { if (!preg_match(“~^(?:f|ht)tps?://~i”, $url)) { $url = “http://” . $url; } return $url; } ?> <a href=”https://wordpress.stackexchange.com/questions/275288/<?php echo … Read more

Categories post-meta Tags post-meta

get_post_meta() not work for the first post inside the loop

In that case try to create custom sql query like this. global $wpdb; $query = “SELECT meta_value FROM wp_postmeta WHERE post_id=your post id AND meta_key=’class’; $results = $wpdb->get_row($query) ; echo $results->meta_value;

Categories post-meta Tags post-meta

$wpdb class updating meta_value using Ajax [closed]

$wpdb class updating meta_value using Ajax [closed]

Categories post-meta Tags ajax, meta-query, post-meta
Older posts
Newer posts
← Previous Page1 … Page31 Page32 Page33 … Page51 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