Questions tagged [post-meta]
Post meta is a data set containing additional core as well as custom post information.
1,971
questions
1
vote
1
answer
293
views
Convert post meta to custom taxonomy?
I'm working on a site update for a client. The current version of their site stores a lot of information within custom post meta fields, added as plain text boxes using Advanced Custom Fields. We ...
2
votes
1
answer
4k
views
How to duplicate entire custom post type
I have a custom post type created in my theme, the post type is called "Portfolio". I would like to entirely duplicate this custom post type and give it the name "Projects" so it ...
1
vote
1
answer
239
views
How to use update_post_meta() function properly?
So I am working on a something like a plugin in my custom wordpress theme, and and in an options page I have a form whose action is the php file _options.php, in normal manner some data will be sent ...
1
vote
1
answer
347
views
Copy content stored in meta to post content
I'm working on a site that had an existing theme that used meta fields to store blocks (bad practice IMO but pre-block editor).
The problem is there are over 300 posts and all the different "...
0
votes
1
answer
276
views
How to exclude posts by meta key value in the_post_navigation next prev links?
Context: We created a plugin, that allows posts to be either in web, mobile app or both. This is done via meta key. When shown only in mobile app mode, then its hidden from web. The plugin code, that ...
0
votes
1
answer
93
views
Custom attachment function not working in v5.4.2?
I have a function that I re-use in a number of custom themes when required to fulfil a customers need. I understand this can be achieved now with repeaters in ACF Pro but as I had a working function, ...
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
2
answers
469
views
Can't save meta box data in Wordpress using custom post types
I've created a meta box. The code is:
/**
* Add meta box
*
* @param post $post The post object
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes
*/
function ...
1
vote
1
answer
603
views
INSERT ON DUPLICATE KEY UPDATE failes in postmeta table
INSERT ON DUPLICATE KEY UPDATE Mysql query is not working with Postmeta table. It adds new/duplicate rows to the table. I couldn't find a way to solve this. I need to use this as part of a bulk import ...
-1
votes
1
answer
422
views
How we insert values into database using metabox Wordpress?
function Review_Form(){
?>
<form action="" method="post">
<div class="container">
<h1>Add Review</h1>
<hr>
<label for=&...
1
vote
0
answers
624
views
A better way to add a meta box to custom post types
Id like to customize the UI for adding and editing a custom post type such that each custom field is included as a separate input field on the "new post" and "edit post" forms (as ...
1
vote
1
answer
241
views
How to break meta values into different items and avoid duplicates?
I'm trying to build a filter for a custom post type page. The custom post type has a metabox that allows inputting of different authors.
I am displaying the post names in a dropdown like this, using ...
0
votes
1
answer
55
views
$post->post_meta not pulling any post in wordpress/php
I have a function in php as shown below:
function hello_world( $post ) {
echo '<pre>'; print_r($post); echo '</pre>'; // Line A
echo '<pre>'; print_r($post->post_meta); ...
0
votes
0
answers
83
views
How to get the total of two meta values from different meta keys?
At post meta I have two meta keys: 'old_views' and 'new_views', so I need a function to get the total value of these both combined and save it as a new meta key called 'total_views'.
For example:
'...
0
votes
1
answer
831
views
Insert, update or remove data from database (usermeta)
I have a situation here. I'm writing a custom plugin for WordPress. I'm dealing with an issue:
I'v created a metabox for Custom Post Type with add_meta_box and with a callback function where I ...
0
votes
0
answers
29
views
How to securely controlling data without keeping it in postmeta?
I'm looking for another alternative instead of keeping the data in the post metain the post like plugin I developed for wordpress. I want to save the likes of the posts to a database and then show it ...
0
votes
1
answer
223
views
show most viewed post
I have blog post counts which happen when a user views a blog post via ajax and the rest api.
In the database I have a meta key and value like so:
table: wp_postmeta
post_id: blog post ID
meta_key: ...
0
votes
1
answer
32
views
Values from meta-box not on $_POST
I have a meta-box for a cpt and can't get the values from the form to update_post_meta
cpt declaration:
function hgod_fichas()
{
$labels = array( … );
$args = array(
...
1
vote
1
answer
1k
views
WooCommerce order refund get qty refunded
I have some custom meta data bound to a product which I want to increase the count of when an order is refunded. When a refund is issued you can of course only refund some or all of the total quantity ...
0
votes
1
answer
101
views
After updating the custom post type, metafields disappear from the post.php edit menu, how do I fix it?
Internet does not have a solution for this specific condition. First I create a new post as below:
$user_suan = wp_get_current_user();
$args = array(
'author' => $user_suan->ID,
...
0
votes
1
answer
182
views
Add post meta data date to event
I created a post metabox that uses the datepicker to pick a date value. I got as far as adding the metabox and getting the datepicker to work but other than that im struggling to get the data saved ...
0
votes
2
answers
2k
views
Show the "ratingValue" and "ratingCount" values of KK Star Ratings Plugin
I want to display the "ratingValue" and "ratingCount" values generated by the KK Star Ratings plugin (Github).
I made a JSON-LD SoftwareAplication and here is the code I use in function.php:
...
0
votes
1
answer
276
views
get_post_meta not working when variable used for post ID
I think I've read every suggested article on this topic and there are some similar but nothing seems to solve my problem. It seems like it should be simple.
I just want to be able to use ...
0
votes
1
answer
90
views
"BS_" rows in postmeta table
I am pruning my WordPress site's MySQL database and noticed that there are thousands of rows in the postmeta table with the prefix "BS_".
BS_author_type
BS_guest_author_name
BS_guest_author_url
...
1
vote
0
answers
37
views
Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
I want to make Wordpress faster. So, instead of using multiple templates, I want to put sidebar(html), small css file(syntax highlighter, prism.css css content as inline directly to post, to reduce ...
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
1
answer
121
views
Creating a custom post type upon registration for a specific user role
Can anyone help me to create a custom post type content when a new user is registered? But the user should be of specific role only.
I have been searching but couldn't find any solution.
0
votes
1
answer
827
views
Delete post meta by serialized meta value
I have some post meta entries which I like to delete from the database. The delete_post_meta() function seems the way to go:
delete_post_meta( int $post_id, string $meta_key, mixed $meta_value = '' )
...
1
vote
1
answer
244
views
Dynamic tagged image galleries
I'm creating a website for a theater company, using Elementor, ACF, CPT UI, and Jet Engine.
One custom post type, "productions," includes an ACF gallery of production images. Another Custom Post Type,...
1
vote
1
answer
691
views
Restrict Access to Posts based on Custom User and Post Meta Data
I have a custom Post Type called Club Pages, and a custom role called "Club Leader". Club Leaders currently can only read, modify, and delete all Club Pages posts. However, there are many different ...
0
votes
1
answer
1k
views
How to save a meta_value as a numeric value after I retrieve it via update_post_meta?
I tried things like $meta_rwp_user_score = (number_format_i18n($meta_rwp_user_score, 2)); , but this is not working. Where do I use that?
<?php
$meta_rwp_user_score['meta_rwp_user_score'] = ...
1
vote
1
answer
768
views
How to update custom field in WooCommerce
I have added 2 custom fields in a WooCommerce installation using the instructions on this link. It works to save the values but I'm having some problem changing/updating values.
Here is my code that ...
0
votes
0
answers
17
views
Check if any meta on the post has value then display content
I know how to use the conventional get_post_meta, and I usually call it with each field separately. Is there a way to use them all at once? For example, use an if statement to display content if any ...
0
votes
1
answer
31
views
Using zip code to display custom data in Admin Order Details
So I am just trying to display which area of the city a postal/zip code is located in for each order.
I have managed to pull all the correct data and thought I add it sorted out until I realized the ...
0
votes
0
answers
77
views
Remove "Category:" from Post meta
I need to remove the word "Category:" from in front of the actual category name/link. I have checked every answer here and on other sites, and none of the answers work on my site...I have tried many ...
0
votes
1
answer
293
views
Issue migrating a checkbox-type meta field to the block editor
I'm trying to add Gutenberg support to a plugin that registers a custom post type with a checkbox-type meta field called _meta_restrict, while maintaining back-compatibility with the classic editor at ...
3
votes
0
answers
217
views
How to save a ToggleControl value in a meta field?
I registered a boolean meta field called _meta_restrict in a custom post type:
PHP:
function register_meta_fields() {
register_post_meta( 'custom_post_type', '_meta_restrict', array(
'...
1
vote
0
answers
60
views
How do I Implement Atomic Update of Post Metadata?
I'm building a site in which my logged-in users can "love" and "collect" posts. The number of loves and collects are stored within the post metadata using get_post_meta() and update_post_meta().
...
1
vote
1
answer
1k
views
Custom Meta Box not Saving in Posts with Gutenberg Editor
I've read quite a bit of documentation around it, tons of other answers here, but I can't seem to discern why the custom meta box I'm trying to add to posts (and pages, but let's start with one at a ...
0
votes
0
answers
2k
views
How to speed up post list slowed by update_meta_cache()?
Having run Query Monitor on my site, the post list for a custom post takes 18.17s. Query Monitor advises 2 Slow Queries, including...
SELECT term_id, meta_key, meta_value
FROM wpcxt_termmeta
WHERE ...
0
votes
1
answer
355
views
How to Display Image Caption but Not Alt Text
I'm trying to display images with their caption, but when I do it displays both the caption and that alt text. I've tried to use unset( $fields['image_alt'] ); to hide the alt text, but it does ...
0
votes
1
answer
22
views
if in category but only with post meta
Working on an if statement to display text only if it's in a specific category WITH specific post meta. If the post meta doesn't match but it's in this category, the text should not display. This is ...
2
votes
0
answers
317
views
How to store Gutenberg ColourPicker RGBA as metadata
I'm trying to build a sidebar plugin for Gutenberg which uses the ColorPicker component to store a chosen rgba value in metadata using withSelect and withDispatch (I'm testing below with the hex value)...
0
votes
1
answer
224
views
Migrating meta_key and meta_value from old theme to new one
I've just installed a new theme for my wordpress website. ( Jannah Newspaper Theme, to Bimber )
My website is a platform for posting music videos. Jannah Theme have stored all my embed video posted ...
0
votes
0
answers
230
views
URL from get_post_meta() is broken my URL
I'm just another biginner on PHP and wordpress. Well, I've used another code to get meta data and use it as a link in my blog. Everything is fine, but the link is incorrect, wordpress add the website ...
1
vote
1
answer
491
views
How to display singular form of category name?
I have the following code to show the names of the categories for a single post. My categories are named in the plural (i.e. articles, letters, translations, commentaries, etc.), but in this function ...
0
votes
1
answer
438
views
Display posts from multiple value in meta separated by comma
I have got main product with meta key: addons and meta values in this key: 129456,968945,495435 Each of these three numbers is the key with these meta values. For example:
Post 1: meta_key: ...
0
votes
1
answer
347
views
How to select a paragraph other than the 1st to be the post's excerpt?
My WordPress website has 3 paragraphs and one featured image in a post. How do I make the last or last before para to be the post description??
Are there any plugins to do that? Am already using All ...
1
vote
1
answer
998
views
How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
Sorry guys, had to post this again as site wouldn't let me respond to comments (new account).
I have been working on some code to decrease quantity of a variable product based on the numeric values ...
1
vote
1
answer
382
views
Add a date updated/date modified option using custom fields
I run a news website, and I think there are considerable benefits to adding a last date updated option to it. However, everything I see online is for replacing the published date with the date ...