Questions tagged [post-meta]

Post meta is a data set containing additional core as well as custom post information.

Filter by
Sorted by
Tagged with
0 votes
1 answer
863 views

Use WP_query to match post types based on custom field values

i'm trying to query posts from the post type Product that match with the current post in the loop from the post type Item, based on the custom fields product-ean and item-ean. For example: i have a ...
0 votes
1 answer
1k views

Rename image filename using 'media_handle_upload'

I need to rename images uploaded by the user when they post on my site. I have a code that works perfectly to save the image and make it part of the post. But I want the images to be renamed to have ...
0 votes
1 answer
1k 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 ...
0 votes
1 answer
674 views

Proper Way to Sanitize Meta Input

I have a meta field which gets displaed in the admin panel look like: $field = get_post_meta($postid, 'field_name', true); ?> <input type="text" name="field_name" value="<?php echo (!empty($...
0 votes
1 answer
1k views

Blogposting Schema & Structured Data without plugin

I would like to add blogposting schema markup so each new post is automatically optimized for rich data. Some code on the web is messy and needs updates per each post, also plugin is not best option ...
0 votes
1 answer
1k views

Metadata on the WP_Post object

I'm having trouble understanding the behavior of a WP_Post variable (and / or possibly the behavior of var_dump itself). As far as I know, var_dump will inspect all data from a variable. From the PHP ...
6 votes
2 answers
5k views

Update Multiple Post Meta for the Same Post In One call?

How can I update multiple fields/Custom fields for the same post using only one call? Everything I came across are cases of multiple calls of "update_post_meta", for each of the fields. Is ...
0 votes
1 answer
2k views

add action save post type and update post meta woocommerce

I want update post meta in product woocommerce when I save o update the product. I write this function (and insert in functions.php) with save_post_NAME_CPT but don't work. add_action('...
0 votes
1 answer
694 views

WP-API + JS Backbone client - how to update post meta

Using the WP API and Backbone-based JS client, I'm trying to update a post's metadata as follows: var parentId = 96; // the post id var metaData = new wp.api.collections.PostMeta('', {parent: ...
0 votes
0 answers
13 views

SQL query based on two different custom field values

I have custom post type "store" that has two different custom fields: Coutry and City. When in the single country page I list all the stores in that country. What I would like to do is to ...
0 votes
1 answer
2k views

Update post meta without deleting the old entries

$old = get_post_meta($post_id, 'figure_sugsubject_repeatable_fields', true); $new = array(); $figuresugsubjectpositions = $_POST['figuresugsubjectposition']; $figuresugsubjectworkplaces = $_POST['...
1 vote
1 answer
2k views

How to create a meta_query to get all posts with a specific meta data?

Here are the args for my query : $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' =>...
0 votes
1 answer
35 views

Update post meta array - add new, single value

What i'm trying to do - i have meta field in post with array of user emails, i'd like to add new user email(if it's not there already) with each submission of Contact form 7. Here's what i managed to ...
0 votes
1 answer
1k views

How to programatically create a WooCommerce downloadable product?

Is there a way to add, for example, an MP3 file to a WooCommerce product from PHP rather than from the dashboard panel? Looking in the database I see that downloadable_files seems to be a serialized ...
0 votes
2 answers
1k views

register_meta not showing custom post type metabox data in rest api

I have added a custom post type and I want to expose the custom field value in the rest api. As per the docs register_meta can be used. I have created a custom post meta box using the wordpress way. ...
1 vote
1 answer
777 views

Is it possible to store Json data in post_meta and manipulate

I just want to add json data type in post meta field as like in normal database. json data will be in the structure below, Post Name Meta Data 1.Sample title 1 ---> ...
0 votes
1 answer
763 views

How do I delete element from a serialized array upon deletion of a post?

I want to delete an element (post id) from a serialized array associated with a specific meta_key. The following screenshot tells the whole story. What you're seeing are, post ids saved in a ...
0 votes
1 answer
781 views

I need query_posts() to order results first by a meta value and then by post ID

I've read all the WordPress docs that seem relevant, and I've read lots of posts here and on other sites to find an answer to this, but I still can't find a way to do this. I have a custom post type. ...
0 votes
1 answer
1k 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 - ...
1 vote
1 answer
809 views

How to update the title of audio file through its attachment metadata

I am trying to programmatically update some metadata of audio file attached to a post. I have been able to update the artist and album properties of the audio file but title doesn't stick. I can go ...
0 votes
1 answer
809 views

wordpress simple post multi rating with post_meta and user_meta

I am trying to create a multi criteria post rating function with simple form and post_meta and user meta. The Goal when users submits their ratings 2 things should happen: 1.the ratings is stored ...
0 votes
1 answer
745 views

Where is get_post_meta value located?

I'm working on a wordpress website created quite long ago. In the header file I see the following code: <?php query_posts("page_id=63"); while ( have_posts() ) : the_post() ?> <?php echo ...
1 vote
1 answer
982 views

Saving zero as meta value

I have a meta_key called "_ordre" and each time I create a new custom post, a new meta_value is set for that meta_key. The thing is, when I set the value of '_ordre' to 0, the meta_value is not saved ...
0 votes
1 answer
966 views

post_title in save_post action

I use save_post action to save meta field and to check if post title is set. So I check the value returned by empty($post->post_title) but I get true also if I set the title.
0 votes
0 answers
11 views

Custom fields with value not pushing with wp_remote_post to wp site

I want to share current post to another WP site with wp_remote_post function, so i created a post template and then select that to remote site with submit button. I have created code it's working fine ...
2 votes
1 answer
51 views

Block Editor - Meta values not saved, meta changes to empty array on update

Issue TL;DR I have a block that updates meta values, but when I click 'update', the values are not saved for the post. Additionally, the meta values I get from useEntityProp load as an object with ...
0 votes
0 answers
6 views

Add default meta data to a page/post template

Creating a Gutenberg template and populating it with default content is as simple as defining the initial content inside a file of the templates directory of a theme and the defining said template in ...
2 votes
1 answer
4k views

Saving custom image meta fields

I have currently added a custom meta field to upload a media file (image). I can successfully add the upload button to display and it works but I'm having problems saving the field when updating the ...
0 votes
1 answer
1k views

Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete

I am trying to write a plugin that adds a custom meta field to image attachments to give images a credit field. I use the 'attachment_fields_to_edit' and 'attachment_fields_to_save' filters. ...
1 vote
1 answer
1k views

Save an array of values in the post meta box

I created box meta for a custom post type. From the admin edit for the post, I want to enter in multiple values so that it saves as an array so I can then call it as an array from the front end. So ...
0 votes
1 answer
2k views

WordPress AJAX load post metadata in modal

I have a custom page template (front-page.php) and I have a custom metabox which is assigned to this page template. Metabox have 7 sections, and each section have 2 inputs. It looks like: 1. Client ...
1 vote
1 answer
1k 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
1 answer
2k views

Get meta information from post parent

So I am in a single page and I want to get some meta information from a parent page. This code is inside my footer.php: if (is_single()) { global $post; $parent = get_post_achestor ( $post-&...
0 votes
1 answer
858 views

Update Post metafield of specific categories

I have some meta fields in WordPress created by theme and i want to update it by using php. The metafield stores url and i want to add some string after current url in custom meta. i tried these ...
0 votes
3 answers
1k views

Counting number of identical meta keys

Im looking to count how many meta keys exist within a post, because each time a specific user action happens, a new meta key is created with a date in it. I have this, which does not return anything (...
0 votes
1 answer
1k views

Create action running on trashed_post hook to modify post_meta value

I have a custom post type that always do math operation to its post_meta and other custom post type post_meta. For example: post-type 1 = cpt_product_order post-type 1 post_meta = ...
0 votes
0 answers
13 views

Normal Posts and Custom Posts with Date Query

I have a custom post type with a date query and these posts only shows on the post archive list when I create a normal non custom post and save this normal post then both the custom post and normal ...
0 votes
1 answer
61 views

getEntityRecords/useEntityRecords: How to use CPT metadata?

I use getEntityRecords as described in the official data API tutorial (https://learn.wordpress.org/lesson/retrieving-wordpress-data-records/). I.e.: const [searchTerm, setSearchTerm] = useState( ''...
0 votes
1 answer
2k views

change attachment custom field onChange event

The form is in post creating window. Ajax is posting values, but the values doenst renews. Where can be problem ? Ajax <script> function dynamic_Select(field, aid, value) { console.log(...
0 votes
1 answer
23 views

Hide username from blog post source code

I discover some of failed login attempts on website i manage, some of it the attackers know the username who published the post, i looked into wp-json and it is not show or leaks anything. but when i ...
0 votes
1 answer
898 views

How to get several fields from wp_query?

I'm going to get several fields from wp_query result. I know about wp_list_pluck() function, but it accepts only one field paramether. How to get several ones if I'd like to take several parameters ...
0 votes
0 answers
20 views

wp_update_post function exclude specific field

I am using a function to update the default post and this function updates the language post publish date and some fields. it's working fine but the problem is that our meta_post field "_mydomain&...
1 vote
1 answer
1k 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', '...
0 votes
1 answer
41 views

Cannot read properties of undefined (reading 'useEntityProp')

I'm working on a custom block and want to store some values in meta instead of the properties. So I followed the instructions from here Meta Boxes | Block Editor Handbook but after building the block ...
0 votes
1 answer
2k 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 ...
3 votes
2 answers
6k views

Displaying Meta Box Image

I have some problems displaying info from my custom meta box in my custom post type single. I'm using Reusable Custom Wordpress Meta Boxes by Tammy Hart. I'm able to display the textfields using this:...
0 votes
1 answer
885 views

Get original post ID after wp_insert_post

I have a plugin with several CPTs (we'll call them CPT-A, CPT-B, CPT-C, and CPT-D). All CPTs have custom fields. In CPT-D, the user is able to make a selection and assign a post in CPT-A, CPT-B, and ...
6 votes
1 answer
2k views

Admin Area Custom Type Search By Meta Fields Without Title & Content

I have a custom post type that uses several meta fields. In the admin area I would like to be able to search by those meta fields. I have implemented this currently in my functions.php with this code: ...
0 votes
1 answer
1k views

How to add a post's view count into the WordPress API response

This is my first time working with Wordpress APIs, and i'm not a PHP developer. Essentially our client just wanted us to display WordPress articles in our react-native app with simple data like the: ...
0 votes
0 answers
11 views

Filtering Tabs in a Custom Post Type's Edit Page

I am using LearnDash to create courses on WordPress. A key thing is that I have other non-admin instructors that will also help me create lessons. The thing is, the lesson edit page has a "...

1
2 3 4 5
40