5

This should work out of the box, as long as the "unique" parameter of add_post_meta() is false. add_post_meta($id, '_dates', 2, false); add_post_meta($id, '_dates', 3, false); add_post_meta($id, '_dates', 4, false); then somewhere else $dates = get_post_meta($id, '_dates', false); Now $dates should be an array of your 3 values.


3

Turns out meta_query was the way to go. This is the code I used to make it work. add_action( 'pre_get_posts', 'filter_posts' ); function filter_posts( $query ) { $now = date("Y-m-d H:i", strtotime('+2 hours')); if( is_category() && !is_admin() && $query->is_main_query() ) { $query->set( 'posts_per_page','10' ); ...


2

You can use the default WP function get_post_meta to get meta from the post, here is the link to the official documentation https://developer.wordpress.org/reference/functions/get_post_meta/ For example get_field('slb_first_name', $post_id ) must be replaced with get_post_meta($post_id, 'slb_first_name', true)


2

My question is, is there a similar selector for when you don't know the post type of a post beforehand? No, at the current time of writing there is not. The fundamental problem is that the REST API doesn't provide a generic mechanism for getting a post type given a post ID. You can retrieve a post and it will say post but to do this you need to know the ...


2

You could use meta_query, it can handle arrays and strings. So something like this // get location meta, will be easier to determine what is the type of value $location = get_post_meta(get_the_ID(), 'Location',true); $posts = get_posts([ 'posts_per_page' => 10, 'post_type' => 'post', 'post_status' => 'publish', 'orderby' ...


2

This is the normal behavior. ACF field value will not be added directly in your post until you save it. I've been facing this "issue" lately. this is because you have created your field after your posts. So, your posts don't have the associated value. load_field doesn't add values on existing post, it only add your value on the post form edition. ...


2

Is there a smart way to meta_query so it matches just "IS, but not "TS-IS"? The WordPress meta query class (WP_Meta_Query), which among others, is used with the posts (WP_Query) and users (WP_User_Query) query classes, supports REGEXP (since WordPress 3.7) as the compare value, so you could use that with a RegEx (regular expresion) pattern ...


2

<ul> <?php $recent_posts = wp_get_recent_posts(array('post_type'=>'news')); foreach( $recent_posts as $recent ) { echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </...


2

Ideally you should include the code you've already tried with your question so we can help with that, just a tip. :) But if you're using the code from that other post as-is, the change would be to this bit: add_filter( 'the_title', 'wpse33385_filter_title', 10, 2 ); function wpse33385_filter_title( $title, $post_id ) { if( $new_title = get_post_meta( $...


1

if you need to turn it into an array of IDs then it is already an array of IDs, you don't need to do any work on it, it's already in the perfect form to go straight into the terms parameter e.g. 'terms' => $terms, The only thing to be mindful about though, is that get_field is not a WordPress function, it's an ACF function, and you will need to ...


1

As you can see in the documentation, neither leasenum nor an arbitrary meta key is a valid value for orderby. If you want to sort by a single meta value, you should set meta_key to that key, and then you can set orderby to meta_key (or meta_value_num if the value is numeric) to sort by that key. This is also described in the documentation: Note that a ...


1

but remaining values (checkbox, select, images) are not getting saved I believe those fields are also getting saved, but you are just not displaying them correctly. And you should always escape input/textarea values, e.g. use esc_attr() for single-line inputs and esc_textarea() for textareas (multi-line inputs). So to make your code work correctly, try ...


1

This is purely an HTML issue. The problem is that you've tried to indicate the selected item by setting a value="" attribute on the <select> element. That's not how <select> works. To mark an option as selected by default the <option> tag needs to be given the selected attribute. For example, you are outputting this: <select id=...


1

To modify the theme's registration would be possible, but definitely not recommended. It is likely that you would only be able to add your additional fields by directly modifying the theme files, especially with something like user registration. It would be a pain to maintain if you intend to keep your theme up to date. What I recommend doing instead is: Add ...


1

Your query args are not quite correct. When you want to order by a custom field, you need to specify a meta_key argument, and set your orderby to the kind of ordering you need. For example: $args = array( 'tax_query' => array( array( 'taxonomy' => 'topic', 'field' => 'slug', 'terms' => 'movie',...


1

This is the PHP serialization format, and is used to serialize arrays for storage in the database. Core WordPress functions take care of this process for you. You just need to use an array as the value. For example, this: $schema_article = array( 'headline' => 'aaa', ); update_post_meta( $remote_id, '_schema_article', $schema_article ); Will save ...


1

Based on the screenshot I assumed is var_dump of your $item The code should look like <?php $item = get_post_meta($post->ID, 'occupationalCategory', false); ?> <?php print_r( $item['occupationalCategory'][0] ); ?>; <?php print_r( $item['occupationalCategory'][1] ); ?> $item contains array, with a element which key is '...


1

When you do this: '_related_posts': [post.id], you're actually overriding the entire array or the meta value, so to instead append an item to the existing array, you can use the spread (...) syntax like so: '_related_posts': [ ...meta._related_posts, post.id ]. But you may want not want to update the meta if the selected post ID is already in the current ...


1

I mark this as answered. Go to any page or post and click on edit and follow the arrows below. By default, the custom fields option is hidden on the post edit screen. To view it, you need to click on the three-dot menu at the top-right corner of the screen and select ‘Options’ from the menu. Reference: this site


1

I believe that your syntax is wrong in the variables you set up in your foreach loop. Because you're referencing an object and not an array, you need to use this format: $author_ID = $value->ID and... $value->display_name We also discovered that the foreach loop isn't necessary, so I'm removing it from the answer. The other issue is how you're ...


1

You can use the popular ACF plugin to dynamically add fields and field groups to the product page. Start with frequently asked questions.


1

In this example , suppose expiry date is (19 April 2021) AND also your Today Date is equal like(19 April 2021) or greater then Like Tomorrow date (20 April 2021),So You will get all the posts from today's date, Here, date format is (dd-mm-yyyy) as defualt (19-04-2021). But, as your requirement format ('d F Y') like this (19 April 2021). So, as per my example ...


1

You have to add the code to your template to display the fields. They don't automatically output to your page. Assuming you're using the text field, you need to add the following: <h2><?php the_field('heading'); ?></h2> Chage the text 'heading' to the name of your custom field. Normally, If it's the home page, you can edit the template ...


1

the_title filter takes two parameters, one of them is the ID of the post for which it was called. Something like that should work. add_filter( 'the_title', 'se385007_title_filter', 20, 2 ); function se385007_title_filter( $title, $post_id ) { $new_title = str_replace( "[geo_name]", "[geo_name post_id=$post_id]", $title ); return ...


1

I believe that's expected. get_the_ID() returns post_ID from main query, and in a single page will return post_ID for that page. The way you filter post title affects all post title that'll be rendered in a page regardless of their actual post_ID. Since the problem is in a widget, you need to get the ID from its query (not main one). I'd try to use the ...


1

This seems to work for now.. Added onended="onEndVideo()" to the video element like so. <?php $mrssfeed_url = get_post_meta(get_the_id(), 'nowthisearth_media_url', true);?> <video onended="onEndVideo()" id="nowthis-video" class="nowthis-video" style="" width="1280" height="720" ...


1

Use in_array(), like this: $search = [ 'AAA', 'BBB', 'CCC', 'DDD' ]; $meta = get_post_meta( $post->ID, 'MY_CUSTOM_KEY_A', true ); if ( in_array( $meta, $search ) ) { update_post_meta( $post->ID, 'MY_CUSTOM_KEY_B', 'ZZZ' ); }


1

When registering the Custom Post Type, ensure custom-fields is present in supports => array('editor','title', 'custom-fields'). It's the legacy wording of meta fields and is commonly mistakenly omitted when declaring supports in CPTs. After you make the above change, your Team CPT should work with meta values. You still may encounter in Gutenberg ...


1

The accepted answer worked fine except it messed up the ordering of Scandic (finnish / swedish…) characters. The letters Å Ä Ö should be at the end. Here's how it works with Scandic alphabet. add_filter( 'posts_orderby', function( $orderby, \WP_Query $q ) { if ( 'wpse_last_word' === $q->get( 'orderby' ) ) { $get_order = $q->...


1

I found an clean solution in WordPress core. WordPress developers already had this problem for search in attachments _wp_attached_file meta and they fix this issue in this function: _filter_query_attachment_filenames() Taking the idea from this function, I wrote the following code to search in metadata: /** * Enable Search in postmeta and posts ...


Only top voted, non community-wiki answers of a minimum length are eligible