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
133 votes
12 answers
500k views

How do I retrieve the slug of the current page?

I am trying to retrieve the slug of the current WordPress page outside the loop. The title of the page returns with wp_title (), but how can I get the slug? <li> <a href="/slug-of-current-...
  • 1,689
66 votes
3 answers
94k views

Query all posts where a meta key does not exist

I am trying to get a query to retrieve all the posts where a specific meta_key does not exist and then create it. I am having problems finding those posts as the query I am testing does not seem to ...
  • 807
47 votes
10 answers
101k views

How to only display posts whose meta_value field is not empty?

Three people have already tried to solve this, and we're coming up nil. I want to show only posts that have a value in the meta_key 'featured_image'. So... if 'featured_image' is not empty, show the ...
  • 707
46 votes
6 answers
131k views

Get posts by meta value

I would like to list all posts that have a key of cp_annonceur with the value professionnel.
  • 481
45 votes
7 answers
60k views

Most efficient way to get posts with postmeta

I need to get a bunch of posts with their metadata. Of course you can't get metadata with a standard posts query, so you generally have to do a get_post_custom() for each post. I'm trying with one ...
37 votes
11 answers
26k views

Can the Next/Prev Post links be ordered by menu order or by a meta key?

I have a series of posts that are ordered by a meta_key value. They could also be arranged by menu order, if necessary. The next/prev post links (generated by next_post_link, previous_post_link, or ...
36 votes
4 answers
75k views

what is the correct way to compare dates in a WP query_posts meta_query

I have a query_posts call in a WP template. Through the use of the More Fields Plugin I can give the site admin the ability to create an event (custom post type) and then enter a date which is ...
34 votes
2 answers
37k views

How to hook update_post_meta and delete_post_meta?

I'm still struggling to get my head around this whole hooking into things, so I'm really stuck on trying to do the following task: If update_post_meta is fired then check to see if the meta_key is ...
  • 12k
33 votes
2 answers
8k views

Explanation of update_post_(meta/term)_cache

I was reading over some best practices from 10up and they mention setting these two flags to false in a WP_Query ( depending on what you're querying ): 'update_post_meta_cache' => false: useful ...
  • 19.8k
33 votes
2 answers
58k views

How to extract data from a post meta serialized array?

I found an XML to WP decoder script that stores the data as an array in a custom meta field. What is the best way to extract the information? For example how could I display the "Manufactured in" ...
  • 3,478
32 votes
3 answers
34k views

Can I exclude a post by meta key using pre_get_posts function?

I see many people prefer to use pre_get_posts hook instead of query_posts. The code below works and shows all posts which have meta key "featured" function show_featured_posts ( $query ) { if ( $...
  • 341
32 votes
5 answers
27k views

Post meta vs separate database tables

When developing plugins that requires data storage, what's the pros and cons of using one method or another ? The explanation given in the codex is not detailed: Before jumping in with a whole new ...
32 votes
4 answers
70k views

Advanced search form with filters for custom taxonomies and custom fields

I'd like to build an advanced search form for a specific custom post type, having filters for the custom post types custom fields, custom taxonomies, and for a separate custom post types properties (...
  • 623
31 votes
5 answers
78k views

How to update custom fields using the wp_insert_post() function?

The WordPress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more. What there is no documentation for is how to ...
31 votes
1 answer
33k 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 ...
26 votes
5 answers
40k views

Can wp_query return posts meta in a single request?

I would like to create a wp_query that would return posts meta inside the posts array. $args = array ( 'post_type' => 'page', 'meta_key' => 'someMetaKeyName', ); // The Query $query = ...
  • 449
23 votes
1 answer
20k views

order by numeric value for meta value

I have read countless posts on ordering data by numeric value ( as opposed to string - it i have a numeric meta value and it gets ordered like this 1 11 12 2 233 etc as opposed to the way i want it I ...
  • 2,984
22 votes
3 answers
43k views

Attaching taxonomy data to post with wp_insert_post

I am trying to implement a front end posting system which shows taxonomy data in several dropdown select fields. Each of the dropdowns is named by using the "name" $arg in wp_dropdown_categories(). ...
  • 1,964
22 votes
4 answers
14k views

Passing error/warning messages from a meta box to "admin_notices"

I have a simple meta box that updates the post custom fields (using update_post_meta()). How can I send a error or warning message to the next page after the user publishes/updates the post and doesn'...
  • 13.5k
19 votes
1 answer
42k views

How to save an array with one metakey in postmeta?

I have an array saved in postmata, each array key become a metakey. I want to change the code to save the whole array with one metakey. How to do that? Thanks! $poddata = Array( 'pod_id' => $this-&...
  • 1,677
19 votes
2 answers
60k views

Add "upload media" button in meta box field

I have a custom post which has a meta tag that needs to be using a file upload (for video files). I am wondering, what is the correct way of adding an "Upload" button that points to the WordPress ...
  • 485
18 votes
7 answers
13k views

WordPress is stripping escape backslashes from JSON strings in post_meta

I thought I was making my life easy and being future-conscious by saving some content as bits of JSON in custom post_meta fields. Unfortunately, WordPress doesn't agree and is making my life ...
17 votes
4 answers
43k 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 ...
  • 929
16 votes
3 answers
8k views

Why WordPress choose data serialization over json_encode?

In my little age with WordPress, I've seen WordPress itself and its friendly plugins are using PHP serialize() in storing data into db in many cases. But in a recent search I found a serious community ...
16 votes
3 answers
27k views

Meta query with boolean true/false value

I'm trying to show all rental properties, first by all properties that have not been rented, and then by all properties that are currently rented. There is a custom post type 'rent' with custom post ...
15 votes
2 answers
119k views

How can I get the post ID from a WP_Query loop?

I have a WP_Query loop that gets posts of a certain type. These posts have custom post meta so I need to be able to get the ID of the post without echoing it so I can display that post's meta. How ...
14 votes
2 answers
32k views

How to check if post meta key exists or not in wordpress database

I want to check if post meta key exists or not, out side of the loop. Is there any WordPress function to check if post meta key exist or not in WordPress database. I have to check this outside the ...
14 votes
6 answers
41k views

How to make search include data from wp_postmeta?

I have a site using Advanced Custom Fields to create and store various bits of relevant info. These need to be included in the main general search, which by default only searches the title and main ...
13 votes
3 answers
6k 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? ...
  • 235
13 votes
3 answers
17k views

Why are simple updates to wp_postmeta's "_edit_lock" so slow?

In our MySQL slow query log, the cumulatively slowest query is a simple update to wp_postmeta. Here's an example: UPDATE `wp_postmeta` SET `meta_value` = '1392835505:386' WHERE `post_id` = 94705 ...
  • 1,391
12 votes
6 answers
34k views

Check if Post Title exists, Insert post if doesn't, Add Incremental # to Meta if does

I already have a function where a user submits a form and creates a custom post... <?php $postTitle = $_POST['post_title']; $submit = $_POST['submit']; if(isset($submit)){ global $user_ID; ...
  • 537
11 votes
5 answers
29k 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\...
  • 113
11 votes
5 answers
22k views

How do I query for posts by partial meta key?

I have a function that stores the "like" status for a post as post meta. I want to associate that "like" with the user that liked it, so I setup a custom field called "like_status_{user_id}" (where {...
11 votes
1 answer
5k views

Difference between meta keys with _ and without _ [duplicate]

In wp_postmeta table I noticed that some of the keys are with '_' (underscore) prefix and and some are without _ What is the major difference between these fields and how they can be used while ...
  • 348
11 votes
2 answers
12k views

Use REGEXP in WP_Query meta_query key

I know I can use REGEXP in WP_Query like this: $query = new WP_Query(array( 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( '...
10 votes
6 answers
34k views

Get post with multiple meta keys and value

I am trying to fetch a post based on the following meta keys. post_code with 432C location with XYZ Both belong to a CPT. I'm trying to fetch the Post with both these meta_values. I Don't Want an ...
10 votes
2 answers
18k views

Correctly delete posts with meta and attachments [duplicate]

I am having an overview of custom post types. These have custom tax and also an attachment. In my overview I need to provide links to delete the entries. With that I also need to delete the ...
  • 179
10 votes
4 answers
13k views

Orderby meta_value only returns posts that have existing meta_key

I have the following wp_query: $args = array( 'post_type' => 'news', 'orderby' => 'meta_key', 'order' => 'ASC', 'meta_key'=>'custom_author_name', 'post_per_page'=>-...
  • 3,173
10 votes
1 answer
2k 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']...
  • 483
10 votes
4 answers
11k views

Order by meta value or date?

Got a custom field called startDate but its only on a few events. I was wondering if it isn't set for a post I could use post_date to generate the posts list? // if meta_key _postmeta.startDate isn't ...
  • 1,649
10 votes
1 answer
6k views

How to enable revisions for post meta data?

Normally wordpress keeps revision of wp_post table. But for generating a report I need some custom fields to be tracked while any update happens. As custom fields are saved in wp_postmeta table I need ...
  • 101
10 votes
2 answers
11k views

What is "meta_input" parameter in wp_insert_post() used for?

I am inserting some post into wordpress using the function wp_insert_post(). I want to insert some custom fields on each post and reading the documentation I though the meta_info parameter was used ...
  • 105
9 votes
3 answers
17k 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<!--:--><...
  • 91
9 votes
2 answers
52k views

How to update_post_meta value as array

I created new custom field within my nav menu items as multiple select options i used update_post_meta() as below function YPE_update_custom_fields($menu_id, $menu_item_db_id, $menu_item_data) { ...
9 votes
4 answers
8k views

How to add category to: 'wp-admin/post-new.php'?

I want to have a link to create a new post that sets the category also. I have tried wp-admin/post-new.php?post_category=12 and wp-admin/post-new.php?cat=12, but neither worked. I also tried using ...
  • 226
9 votes
2 answers
57k views

Adding meta tag without plugin

Is it possible to add meta title, meta description, meta keywords in every page without installing plugin? My client require not to install plugin. I am curious about this case, all I know is the ...
9 votes
2 answers
23k views

Filtering posts by post meta data

I want to filter posts in such a way that only posts, for which get_post_meta($post->ID, "project_cat", true) (it returns a post ID) is equal to my specified value, are shown. Any way to do this? I ...
  • 771
9 votes
4 answers
4k 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 ...
  • 9,489
9 votes
1 answer
3k views

How to use update_{$meta_type}_metadata filter to modify meta value

I'm trying to wrap my head around the update_{$meta_type}_metadata filter, in order to modify both post and user metadata before database insertion. After reading the docs and the core, it seems to ...
9 votes
2 answers
274 views

WordPress retrieving meta data for all custom post types in list view

I'm having an issue in WordPress where PHP is dying. I've increased memory, but the PHP process jumps to 100% CPU usage then dies and Apache throws a 500 error. I've tried to get Apache to log ...

1
2 3 4 5
40