Articles of get post meta

Trigger JS in custom meta box if a featured image is loaded/exists

Playing with WordPress customization I created a meta box with several others that report back details of the post. One meta box evaluates the featured image but I am having trouble figuring out how to fire the AJAX in the content of the meta box. At first I thought I would need to look into […]

Create a random unique 6 digit number as custom field for custom post type

I use the following function to create a random unique 6 digit number and save it in a custom post type meta field. I am unsure about the use of rewind_posts() inside a while loop. The idea is that it checks if the $random number already exists inside any of the existing custom posts. If […]

How can I get_post_meta() in the most efficient way?

I have a custom post type for a real estate site, and the theme displays 9 properties in a grid on the home page. I don’t think its written terribly efficiently – I’m getting about 160 queries on the front page, and only about 20 of those queries are from plugins, so the theme needs […]

How to get custom field image url of specific size

I have a “cmb2” custom field with type->file. and i use it to upload images. If i use: echo get_post_meta( $post->ID, ‘_pf_photo1’, ‘medium’ ); i get the url of the full image (not the medium one). How can i get the url of the ‘medium’ / ‘thumbnail’ and so on…

get_post_meta is returning image id

I’m using this script to get image filename, stored in a custom meta called background: $background = get_post_meta( ’22’, ‘background’, true ); echo $background; But it is returning the id of the image, not his filename.

Why is get_post_meta returning an array when I specify it as single?

The documentation from get_post_meta makes it sound as if the single argument will determine whether or not meta values are returned in an array or not. For example: // If I set single to false, or leave it blank it’s returned as an array [my-meta] => Array ( [0] => my-value ) // If I […]

Need help on creating If-statement for custom meta fields

I’m using WordPress. I have a movie review website called Filmblurb. For my blog posts, I’m trying to create posts with different categories. Under the “Reviews” category, I have a “Details” box that serves as meta information for all my reviews. The problem is when I try to create a post that has the category […]

Why does get_post_meta not work with the posts page?

Looking for a reason why get_post_meta() doesn’t work with home.php. From my reading I understand that it’s a template and not a post or page, per “Custom fields won’t display on my blog page”. The closest page I was able to find from searching was “get_post_meta fields don’t show up on posts page” but alas […]

Ordering posts by metadata

In my plugin, I use these instructions to obtain a list of posts: $args = array( ‘numberposts’ => -1, ‘offset’ => 0, ‘meta_query’ => array( array( ‘key’ => ‘metadata1’, ‘value’ => ’80’, ‘compare’ => ‘<=’, ‘type’ => ‘UNSIGNED’ ), array( ‘key’ => ‘metadata2’, ‘value’ => ‘4.6’, ‘compare’ => ‘<=’, ‘type’ => ‘DECIMAL’ ), ), ‘post_type’ […]

How can I display my custom metaboxes on a custom post template?

I’m fairly new to PHP/wordpress, and this is actually the first time I haven’t been able to answer a question through google! I’m working on getting up to speed with PHP/WP generally, but I can’t seem to learn fast enough to keep up with what we need to accomplish already. Please have patience with my […]