Questions tagged [get-post-meta]

This function returns the values of the custom fields with the specified key from the specified post. It is a wrapper for get_metadata('post'). To return all of the custom fields, see get_post_custom(). See also update_post_meta(), delete_post_meta() and add_post_meta().

Filter by
Sorted by
Tagged with
20
votes
1answer
21k views

How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]

I read this question but it wasn't what I was looking for exactly. I'm new to Wordpress and a little confuse with the functions and everything. How can I get the metadescription in the loop for each ...
12
votes
4answers
29k views

Display Yoast WordPress SEO title in archive template

The WordPress SEO plugin by Yoast allows users to add SEO titles and meta descriptions to taxonomy term archive pages. These are then used in the head of the document. I´m trying to display the SEO ...
10
votes
3answers
4k views

Custom post meta field effect on the performance on the post

I have the posts which have many custom defined meta fields. On posts I am calling them on requirement using get_post_meta. Means for 10 meta fields I am using it 10 times. Am I doing it right? ...
10
votes
1answer
1k views

What is the index [0] for on post meta fields?

Trying to improve my PHP knowledge through test and try! I am confused on [0] arguments at following WordPress PHP code global $post; $custom = get_post_custom($post->ID); $price = $custom['price']...
9
votes
3answers
15k views

How to get custom post meta using REST API

I am trying to create a REST APIs for my wordpress website which is used for facility listing using wordpress job manager plugin. I have registered my custom post , taxonomies in \plugins\rest-api\...
8
votes
3answers
10k views

How to hook a filter to catch get_post_meta when alternate a custom field output?

How to hook a filter to catch get_post_meta when alternate a custom field output? I have fill a custom field(meta data) in a post, just like this: <!--:de-->Nominale spanning<!--:--><...
6
votes
4answers
2k views

What's the point of get_post_meta's $single param?

Looking at get_post_meta() I always have to remember to set the $single param to true. I generally assume I'm setting a value and I expect to get that value back. Retrieve post meta field for a ...
6
votes
1answer
615 views

Using get_post_meta with new_to_publish

I'm trying to read the custom fields set by the user when publishing a new post: function doSomething($post) { $meta = get_post_meta($post->ID); error_log("post meta: ".print_r($meta, true)...
5
votes
2answers
4k views

How to print meta description to posts? [closed]

I want to show my meta description content above posts. But i don't know what function I need to call. Resume: i want to put meta description from Yoast Seo above the posts body.
4
votes
4answers
35k views

if get_post_meta is empty do something

I need opposite of this: <?php if ( get_post_meta($post->ID, 'price_list_category1', true) ) : ?>style="display:none;"<?php endif; ?> In other words I want style="display:none;" only ...
4
votes
2answers
11k views

How we get_post_meta without post id

I want to get my all posts-meta, But on the base of key. For example the main query for getting the post-meta is <?php $meta_values = get_post_meta($post_id, $key, $single); ?> Now i want to ...
4
votes
1answer
1k views

How to hide meta box values from custom fields list?

I have created a metabox : function drama_description_metabox_markup() { global $post; $drama_description_metabox_markup = get_post_meta( $post->ID, 'drama_description', true ); ?> ...
4
votes
1answer
1k views

Check if user already visited this post today

I have a piece of code which measures a post popularity. How would I go about checking if user didn't already visited this post for past 24 hours? Do I need to set a cookie for user and for each post ...
3
votes
5answers
13k views

Get meta_id along with meta_key and meta_value

Is it somehow possible to get_post_meta or get_post_custom and have meta_id returned along with the meta_value? For example: $data = get_post_meta( $post_id, 'my_key' ); // returns this: array( 0 =&...
3
votes
2answers
11k views

display specific custom fields

I have few custom field assigned for each post, like: "Club" with value "club1" "Date" with value "date1" and so on... Now, I want to display from all the custom fields just those 2 " club" and "...
3
votes
4answers
27k views

How to get meta box data to display on a page

I am trying to piece together a Metabox with 3 text editor fields for a custom post type. The box is showing up and appears to be saving on the custom post type entries but I can't get the data to ...
3
votes
1answer
772 views

Add options to featured image

I want to add an option to the featured image metabox. I have found a way to do this here The problem I'm having is saving the value tot the database. Here is what I have tried: add_filter( '...
3
votes
1answer
1k views

How can I display image metadata?

I'm trying to add a filter to the_content that will find all images in the post and append the custom attachment metadata credit to it. Here's the functions I've have: Adds the Credit field to ...
3
votes
1answer
3k views

get_post_meta() unserialize issue - returns boolean(false)

I'm using a simple custom plugin that parses and saves external XML data as a serialized array in a custom field. This works fine, however, when I update the post, instead of the array I only see a ...
3
votes
0answers
756 views

How to use pagination with get_post_meta

I have a Products Page that i am using to add products using custom metaboxes this is the code for my page <div class="container products"> <div class="row"> <?php $...
2
votes
1answer
3k views

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 ...
2
votes
2answers
2k views

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 ...
2
votes
2answers
5k views

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 ...
2
votes
2answers
62 views

loop through all meta keys with get_post_meta

I am building a custom solution where I am needing to obtain all the meta values for a post into an array. I have many "keys". Is there a way to loop through them all without doing this? I have the ...
2
votes
1answer
4k views

Save metabox with multiple checkbox array

I have a requirement where the number of checkboxes outputted in the metabox is not fixed. Had it been fixed, I could've followed any one of the tutorials on the internet which suggests I name each ...
2
votes
1answer
69 views

WP-CLI How to generate a list of posts with corresponding meta values

I created this SQL query to generate a list of posts (which I will use for a CSV Sheet) SELECT p.ID, p.post_content, p.post_title, pm1.meta_value as 'Amazon.com', pm2.meta_value as 'Amazon.co.uk' ...
2
votes
1answer
3k views

Formatting custom meta box date from YYYY/MM/DD to a more readable alternative

QUESTION This is following a previous question that was graciously answered by Milo earlier here - How to sort CPT by custom meta value (date), and return posts month by month In short, I'm having ...
2
votes
1answer
180 views

Meta tags in shortcode

The thumbnail and title shows up as it should, but the post meta displays on the top of the page. What is the correct code for retrieve the post metadata? function evasmat_posts_shortcode(){ $q =...
2
votes
1answer
3k views

get_post_meta returns bool(false)

I've been testing and trying to find where it possibly going wrong but i'm stuck on that part. The get_post_meta() is not returning any of my values, tested with a var_dump(get_post_meta(1)) this ...
2
votes
1answer
112 views

Displaying custom posts only if custom meta box's date is not expired

I have a problem with displaying custom posts - I want each post to show only if a date set in a custom field has not passed. I can't figure out the where I should put the if statement in the code. ...
2
votes
1answer
120 views

Add Post Url to Manage Edit Screen

I'm trying to add a column to the manage screen that displays the Title and url of the post. I got the Title to work but it's not pulling the url. Basically I just want to show the url that's not ...
2
votes
2answers
454 views

How do I access post meta data when publishing a new post in Gutenberg?

I am updating one of my plugins for Gutenberg. I need to check for the presence of a custom post meta field when a post is updated or published, so I've hooked into publish_post: function ...
2
votes
0answers
226 views

get_post_meta returning empty string when data shows in the database

I'm absolutely stumped and I'm hoping this is something stupid that I just can't see because I'm too close to it. Working on an LMS using Sensei. Trying to get the course_id from a lesson. Pretty ...
2
votes
0answers
495 views

Plugin development: get_post_meta is not working [closed]

I am trying to retrieve a post meta data using get_post_meta inside my plugin, but its not working. add_action( 'woocommerce_checkout_update_order_meta', 'some_custom_checkout_field_update_order_meta'...
2
votes
1answer
367 views

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 ...
1
vote
2answers
427 views

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( ...
1
vote
3answers
5k views

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 ...
1
vote
1answer
2k views

Minimising Database Queries when using Advanced Custom Fields

I'm working on a page which lists staff members for a large company and trying to minimise the number of times I'm forced to query the database as it gets quite complex and slow. 'person' is a custom ...
1
vote
1answer
3k views

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 ...
1
vote
1answer
4k views

Trying to get file name

I have a custom meta box to store pdf files. For this input, I'm using type="media" to acess wordpress media library. Now I can't get the file name. Here is my entire loop: <ul> <?...
1
vote
1answer
3k views

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 ...
1
vote
2answers
428 views

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 ...
1
vote
1answer
5k views

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 ...
1
vote
1answer
34k views

How to echo get_post_meta (Fluent-Framework)

PHP beginner here. I purchased the Fluent-Framework plugin, which allows me to easily crease Post Types, Meta Boxes, and Option Pages within my theme. I am having trouble echoing the Meta Boxes, ...
1
vote
2answers
640 views

Display post metadata: “title, category, author, date” with shortcode

How to create shortcodes to the standard post-metadata "title, author, category and date" in order to display it in post-content? E.g. post-content including shorcodes: Lorem ipsum dolor [post_title]...
1
vote
1answer
77 views

get_post_meta pagination

I have custom field, array with multiple values $metas = get_post_meta($post->ID, "$meta_key", false); foreach ( $metas as $metas ){ echo $metas; } Of course this will return an array. ...
1
vote
1answer
352 views

Are multiple values from get_post_meta guaranteed to be ordered?

You can create multiple rows in the postmeta table for a post with the same key, like this: add_post_meta( $post_id, "example_key", "value1" ); add_post_meta( $post_id, "example_key", "value2" ); To ...
1
vote
1answer
114 views

get_post_meta remains empty while looping all menu items and using the ID

I am trying to create some sort of custom menu. Where I list all titles of my pages in the main menu and display the value of a meta box of each of these pages. For some reason the get_post_meta ...
1
vote
2answers
95 views

Where to hook my plugin's action

I'm writing a plugin that every time you: publish a post edit an already published one delete a published post it makes several queries to the database, gets certain post data (title, excerpt, ...
1
vote
1answer
1k views

Custom meta field don't give me numerical value

I'm trying to use the jquery plugin Timeago. With this, I want to countdown from a date (2013/03/04 format) Which is in a custom field. Echo $Begin2 gives me something like : 34 days ago. It's work ...