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().

0
votes
1answer
696 views

get_post_meta image width for lazy load

I'm trying to lazy load a page of images in Wordpress - I've tried the plugins but none of them seem to work(I only want to lazy load image on some pages.) So I'm now trying to do it with a plugin - ...
0
votes
1answer
17 views

Adding Custom MetaData

In Professional Wordpress Design & Development the author states that WordPress features a simple function to add new post metadata called add_post_meta(). This function will attach a piece of ...
1
vote
1answer
54 views

Can't access post meta on new post creation (cpt)

I'm using... function on_CPT_request_publish( $new, $old, $post ) { // ----------------- Start of Function ----------------- if ( ( $new == 'publish' ) && ( $old != 'publish' ) && (...
0
votes
1answer
653 views

get_post_meta slowing down my page load (in a plugin)

I've been working on this project where I need to load events (custom post type) and a whole bunch of meta data for every event. The problem is that page loading times are getting longer and longer ...
0
votes
1answer
1k views

Make Custom Fields Public in JSON - API

How do i make the custom fields public in rest API? I have added a custom field to the rest api. the challenge is - The metadata is returned when i am signed in my browser. if i try as public using ...
0
votes
1answer
728 views

How to get post meta for custom post type and taxonomy

I am trying to access post meta for custom post type and taxonomy using WP_Query and then query the posts with that specific post meta. So far I have tied the following code: $hot_args = array( ...
2
votes
2answers
60 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 ...
0
votes
1answer
1k views

Define category ID using get_post_meta

I need to define the Category ID in my singles page through custom fields so that i can load a different category depending on the page. This is what i have so far and its not working. Any help would ...
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 ); ?> ...
0
votes
1answer
55 views

Allow HTML in Custom Metabox area

I know there are many questions related to my question, but sincerely i was unable to get solution. My question is simple, how can i allow html in textarea in custom metabox on post. So far i have ...
0
votes
1answer
421 views

Display Data From This Custom Media Upload Meta Box?

This plugin is working without any issue on CMS. Now I need to know how to properly display them in my post. Custom Media Upload Meta Box Plugin. $meta_box_media_upload = new Meta_Box_Media_Upload();...
0
votes
1answer
395 views

Editor meta box Showing but not saving

I am trying to create an editor meta box and I have been following tips found in other similar questions without luck in getting the meta box to save and display its content. The meta box shows but ...
1
vote
2answers
751 views

get_post_meta($post->ID) returns empty string when in preview mode of custom post type

I've got my custom post type 'event'. I got tne next code in single-event.php: get_header(); the_post(); echo '<pre>'; echo "$post->ID\n"; var_dump(get_post_meta($post->ID)); echo '</...
1
vote
2answers
3k views

How get post id from meta value

Please look at the picture below. I want to get post_id from meta_value = 93. How can I do that?
1
vote
1answer
49 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' ...
0
votes
1answer
501 views

Access post meta just after publishing

the following code is supposed to store post meta of the recently published post to the variable $temp. But it doesn't, $temp is always empty. This seems to happen because "transition_post_status" ...
0
votes
1answer
568 views

get_post_meta not work in php foreach

i have these codes : foreach ( $ids as $idss ) { echo get_post_meta($idss, 'IMDB', true); } i have search box with Form element that search and find all id ( $ids ) of searched word . i want to ...
2
votes
2answers
350 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 ...
0
votes
1answer
87 views

get_post_meta not working on my custom-function page

I have saved the meta key with the name writer_meta_key and want to retrieve it on my custom-functions page. I can get it on front page and single page but it doesn't work on my custom-function page. ...
0
votes
0answers
73 views

get custom post meta inside custom taxonomy

Hello I create a taxonomy for one of my custom type and add meta field on the backend , I would like to display it in the front end , my code is currently: Could you help me ? /* Add Image Upload to ...
1
vote
0answers
22 views

Get User Post if Private

I'd like to display a message when current user's post is set to private. The code below does this, however only works when you are on the actual post page. I'd like for my message to be displayed ...
1
vote
1answer
74 views

Hide custom meta data if empty

I have a custom field created for WooCommerce products. I am using the below code to create // ADD CUSTOM WOO DATA add_action('woocommerce_product_options_general_product_data', '...
1
vote
1answer
23 views

Where to put meta Keys

Hello im creating my custom checkbox in gallery and i already add that , but save doesn't work , can someone take a look and tell me where should i put meta keys ? function wporg_add_custom_box() { $...
0
votes
0answers
38 views

Get meta values from parent post and save in child post

I have a custom post type "E-Books" with two categories "E-Book Title" and "Chapter Page", and custom meta boxes (table of contents, etc). The E-Book post type uses one page template, and displays ...
0
votes
1answer
1k views

Add a custom class to the body tag using custom fields

There are certain posts where I want to manually append a custom body class using custom fields. How do I go about it appending the class to the body tag when a certain custom field is added to a ...
0
votes
0answers
20 views

Generate post content from meta fields

I have a custom post type (match). Each posts on this CPT has one ore more custom fields. Is it possible to automatic generate the 'post content' with the value of my custom fields on these posts? ...
0
votes
2answers
383 views

Custom Post Status Transition Issues With Get Post Meta

I am trying to figure out to fire a hook for a custom post type called "bananas" when a new bananas post is published. Requirements: Can't use $_POST Need to be able to get post statuses so I can ...
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 ...
1
vote
1answer
343 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 ...
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 ...
0
votes
0answers
12 views

Is it possible to remove a conditional value from WordPress custom metabox

Here I have attached the screenshot from MySQL for easy understanding. In this meta value a: denotes total no of users liked the post. User denotes user with id user-id My question : Is it possible ...
0
votes
1answer
43 views

Reverse Cross-Sells (WooCommerce)

When you run get_post_meta( get_the_ID(), '_crosssell_ids',true); you get an array of all the products that the current product cross sells to. How do I reverse that? To get all the products that ...
0
votes
1answer
49 views

get_post_meta not working with variable as a post_id for dynamically get the postid

I would like to use the get_post_meta to pull a value from a CPT dynamically and then send a email. The problem is that the get_post_meta($post->ID, ... part of the code does not pull the email ...
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 =&...
0
votes
1answer
62 views

copy images from custom field to another custom field

On my wordpress site I have a front end form that allows users to create posts and upload photos for a custom post type 'Property'. Using the following function - $property_sights_value = ...
0
votes
2answers
65 views

why get_post_meta is returning 0?

I'm trying to show all the posts on a page with an audio player in it and for that I'm looping through posts in the following manner: <?php $posts = get_posts(); $ID; foreach( $posts as $item) { ...
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<!--:--><...
0
votes
1answer
114 views

Custom Function to redirect singular post if specific meta field is empty

I have a custom post type People that has several metafields. When the ecpt_bio meta field is empty, the post will link to whatever URL is entered in the ecpt_website meta field on the post archive ...
4
votes
4answers
34k 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 ...
0
votes
1answer
34 views

How to store multiple custom meta box

I am trying to store a multidimensional array of a Quiz where I dynamically add question box. But I am not able to figure out how to store dynamically added question box. The code is below function ...
0
votes
1answer
946 views

add_post_meta doesn't work

I tried this on localhost and it worked, but then I tried to run this on live server (the same template, everything) and it doesn't work. Any help? add_post_meta('39', 'overall', '4');
1
vote
1answer
31 views

How to receive all the meta information of a post ?

How can I get all the meta information of a particular post_id, if my meta_key = 'title' and meta_value = 'My Content Template' meta_key = 'download_url' and meta_value = 'http://www.example.com/pdf/...
11
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 ...
0
votes
1answer
47 views

ajax delete value from custom field array

I have on my page a multi file upload that saves post attachments within a custom field --- if (!empty($_FILES['vidPix']['tmp_name'][0])) { $i = 1; $files = $...
0
votes
1answer
90 views

Save attachment custom fields on front end

I have a front end post form that lets users upload multiple photos and on there I have 2 input fields to try and save custom meta data for each attachment - $vid_pix = get_post_meta($v_Id, 'vid_pix',...
1
vote
2answers
584 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]...
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? ...
1
vote
2answers
55 views

What Wordpress function to use to get meta value by using meta keys?

This is the code: if ($keys = get_post_custom_keys()) { foreach ((array) $keys as $key) { $keyt = trim($key); if (is_protected_meta($keyt, 'post')) { continue; ...
0
votes
1answer
196 views

update_post_meta in loop changing ALL values

I have a button on the frontend that updates the value of post meta on the backend, and it's nested inside a loop. However, on submit it updates the value on ALL posts. What am I doing wrong? ...
1
vote
1answer
71 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. ...