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
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
0answers
37 views

get_post_metadata causing some meta data to fail

I'm using the following code to extend subscription trial lengths, which requires me to modify the metadata. the problem of, other metadata is also failing, such as custom attributes and variations. ...
0
votes
1answer
715 views

Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle

I'm getting custom fields using <?php $meta = get_post_custom($level_2->ID); ?> <?php foreach ( $meta as $key => $value) { ?> <?php echo $key.': '.$value[0].'<br />'; ?&...
0
votes
1answer
351 views

Create Meta boxes dynamically

I followed and created a meta box using all code from this question here: Create more Meta Boxes as needed Basically only two fields are created when you click on Add track button: Song title field ...
0
votes
2answers
748 views

Next and Previous loop

I am making a wordpress site but i need little help, What I have is a function with Next and Previous buttons to list projects, but when i go to the last project the Next button is gone. What I want ...
0
votes
5answers
1k views

get_post_meta returns NULL in front-end, but correct result in back-end

I'm making a custom meta field for posts. In the back-end, get_post_meta works fine and returns the value. In the front-end, it returns NULL: $my_custom_field = get_post_meta( $post_id, '...
0
votes
1answer
697 views

Custom Fields Not Working In Footer

A friend of mine wants the address in his footer to be editable. So I thought to add Custom Fields to a post and then, in the footer call that post (named "Info Post") and get the address from a ...
0
votes
0answers
173 views

Return ACF Field value function

I am working on a function that I would like to access from anywhere within my theme when I call it. I am using the ACF flexible content field and I am retrieving a text field value. The value of my ...
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 ...
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 ...
0
votes
1answer
261 views

Why does get_post() not return anything?

Inside my functions.php I use get_post() or similar (such as get_the_title()) inside some of my functions. It does not return anything. Why? And how to fix that? P.S: And I can not really add ...
0
votes
1answer
138 views

Collect custom post in a calendar

I'm working on a site in which I have incorporated a calendar of events, which also serves as navigation in the events page. That is to say that when I click on a calendar date associated events occur....
0
votes
2answers
65 views

Output meta into arrays

I'm creating a loop which wouldn't output anything visible to the user, but needed to create a calculation later on. I have: // posts for the week mon-fri $week_array = array( 'posts_per_page' ...
0
votes
1answer
177 views

Why is my get_post_meta not properly calling the custom field when attempting to embed a YouTube video?

I have added a custom field to 2 posts in order for a non-developer to be able to post a video link from YouTube, and put the embed id in a custom field to be called by the code below. But when I ...
0
votes
3answers
2k views

get_post_meta as a list for drop down search filter

I was wondering if someone could help me out. I would like to create a dropdown search filter for my wordpress site. I would like the drop downs to be populated by meta_boxes values which i have for a ...
1
vote
2answers
6k views

Where is the key _wp_page_template passed?

When adding custom post meta boxes, I understand that whatever name attribute input you put would be passed through the form into the server. Hence, If I have <input type="text" name="...
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
2answers
2k views

Why is my get_post_meta always empty

I made this action hook which will send an email to the users every time a new post in the custom post type "events" is made. function email_members($post_id) { global $wpdb; $usersarray = $wpdb->...
1
vote
1answer
2k views

Detect meta value changes when post is updated (post_updated)

In my theme, I want to create the function that when a metabox value is changed, the author is notified. Effectively, I have a custom metabox that loops through a certain level of user role (custom ...
1
vote
1answer
140 views

Single-post preview repeats thumbnails in Jupiter Recent Posts widget

I'm using the Jupiter theme version 5.1.8 with WordPress version 4.6. When I preview a single post, the thumbnails displayed by the Jupiter theme's Recent Posts widget are all repeats of the current ...
1
vote
1answer
280 views

Change Post Template based on post meta?

I am trying to figure out a way to use a custom template within my plugin. I would like to avoid using a custom post type if possible. I searched for a way to add my theme file to the dropdown list ...
1
vote
1answer
75 views

How to include template according to meta post value

I'm trying to include a particular template according to the meta value stored for example: If the post meta value is value1, I want to include different template and if it's value2, I want to ...
2
votes
0answers
493 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'...
0
votes
2answers
3k views

get_post_meta for Custom Post Type ( CPT )

Here's the TLDR: Is is possible to get all meta keys from a specific CPT without a database hit for each post? If so, how can I do this the Wordpress way? This seems like a simple thing to do ( at ...
0
votes
1answer
179 views

Get posts with Taxonomy term meta

I want to display posts by categories. In my categories, I just want to display the posts that have the term meta between 100 and 200. How can I do that properly?
-1
votes
1answer
103 views

Display post_meta-by_key on product catalogue

I'm trying to display a custom field in my woocommerce bookshop catalogue. I have added the field "author" and I want to display it after the product title, and before the price. http://www....
0
votes
1answer
930 views

Save Metabox Custom Field Value

I am using this code to show post type dropdown to select available post types but when i submit the post it restores the value back to post, how can i make sure it saves it? <select name='...
1
vote
1answer
3k views

Why is my Custom Meta Box Field Inputs NOT saving?

I have a custom post type labelled 'web_design' and I want my 'web_design' posts to have the following custom fields: 1. 'client' - Client Name 2. 'exlink' - External Link 3. 'datefin' - Date Finished ...
-1
votes
1answer
158 views

How to match data in multidimensional array of post_meta_data?

I am saving user id in post meta whenever someone clicks on like button. $voter = Array( voter => array( 'post_id' => $post_id, ...
0
votes
1answer
1k views

Add custom fields after post/page title

I am using the Headway theme, and I need to add custom field code to page & posttitles. This is what I need to be able to do. example http://www.marbiedesign.nl/_img/customfield.jpg [edit:image ...
0
votes
1answer
94 views

Get all terms linked to a post and include those who not connected from get_terms and sort

I have the following terms in my WordPress project and my post may have connected with some of them or sometimes all terms. A B C D E F My first post (example1) is connected with terms A, B and C ...
0
votes
1answer
95 views

Display posts with empty custom field

How to list post with specific custom field which is empty? I have some posts with custom field 'author', and for some posts that custom field is emty, so I would like to find those posts to delete ...
0
votes
2answers
42 views

Cannot obtain custom meta information

I'm trying to access custom meta data from a custom post type called 'Videos' The following code is on a template page called 'single-videos.php' A custom field called 'Video URL', 'Video Width' and ...
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. ...
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 ...
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 ...
1
vote
1answer
819 views

Populate dropdown from one custom post type inside another custom post type

[Solved -> see last comment in this question] In custom post type CPT_A I am saving first_name and last_name via a custom metabox form field (they are not taxonomies): update_post_meta( $post_id, '...
0
votes
2answers
790 views

String taken from database table post_meta is showing HTML tags on Frontend

I have saved a string in post_meta table in wordpress database with html entities like- <p>Hello <b>Shashank</b>, I have an idea.</p> When I get this string on frontend using ...
0
votes
1answer
128 views

Saved Post Meta Array Returns as String

I am saving an array in post meta using update_post_meta. $arr = array('this', 'or that'); update_post_meta($post_id, 'field', $arr); $ret_arr = get_post_meta($post_id, 'field', true); var_dump($...
0
votes
1answer
902 views

Display an icon with get_post_meta?

I want to display an icon in the post meta data in the loop.php, for each post have a specific meta_value! To be more specific i use this code to display an icon when a new posts has been published ...
0
votes
1answer
37 views

Query Multiple meta

Hi i've looked through the forum but can't seem to find the right solution to what i'm looking what we have is a property website and have various pages setup to show specific types of properties ...
0
votes
2answers
79 views

WP_Query with child element

I have my calendar events, I want to sort them by creation date with the query, but here's the issue: I have a meta key which has child values: First one is $data = get_post_meta(get_the_ID(),'...
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( '...
0
votes
1answer
1k views

Dynamically get the meta key value of a menu item based on it's post ID

I have a menu, that I need to insert an image that have it's path saved in a meta key (_menu_item_img) and associated with a post ID, every menu entry has it's own image, and I need to grab it ...
1
vote
1answer
496 views

Meta Key Value in current-user-only loop

I created a loop for logged-in-users-only which works perfectly for all data except for meta keys. I'd like to be able to also extract meta keys but had no luck so far. This is my loop (based on this ...
0
votes
1answer
172 views

get_post_meta returning broken path in image src

I am using a custom field to store the path to an image and then using get_post_meta() to insert that path into an <img> Here is my code: <img src"<?php echo get_post_meta( get_the_ID(), '...
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 ...
0
votes
1answer
5k views

How to use json_decode a post_meta value? [duplicate]

I have used get_post_meta($post->ID) to get all custom fields for my post since I have many of htem. Some of them were checkbox values and var_dumping the variable gives me this array (size=1) 0 =&...
0
votes
1answer
98 views

Plugin Shortcode value in post

Theme was output with function get_post_meta(get_the_ID(), 'some_value', true); when I try with die(print_r()); function there have some array containing values such as [item_ticket_tailor] => ...
1
vote
0answers
89 views

Default Custom Field Value Automatically Update

I have created a hidden custom field with a php function as its value. Like so -- $value_rating = get_post_meta($Property_Id, 'vr', true); <input type="hidden" name="vr" class="form-control ...