Custom Field: how to save array of multiple key-values in WordPress

I have this kind of data on my database: <wp:postmeta> <wp:meta_key> <![CDATA[property_icalendar_import_multi]]> </wp:meta_key> <wp:meta_value> <![CDATA[a:2:{i:0;a:2:{s:4:"feed";s:86:"https://www.example.com/ics-files/property.ics";s:4:"name";s:20:"IMPORT_1";}i:1;a:2:{s:4:"feed";s:56:"https://www.example.com/ical/property.ics";s:4:"name";s:16:"IMPORT_2";}}]]> </wp:meta_value> </wp:postmeta> As you can see, on meta_value I have two pairs of serialized data "name1/feed1" and "name2/feed2". I wish to add, via custom fields, more instances to that array "name3/feed3)". But I don't know how to do it. I was able to retrive the data so far: <?php $property_icalendar_import_multi = get_post_meta($edit_id, 'property_icalendar_import_multi', true); if(is_array($property_icalendar_import_multi)){ foreach($property_icalendar_import_multi as $key=>$feed_data){ print $feed_data['name']; print $feed_data['feed']; } }else{ esc_html_e('nothing'); …
Category: Web

Repeatable field within repeatable group of fields

Compounding on Saving metabox repeatable fields ... I've created a metabox with a series of fields that are repeatable. However, within those fields, I'd like to create another field named Choices and make that repeatable within each grouping. I was able to setup the additional field and repeat it, but have no idea how to save the value of the new repeatable field. The new field that I was trying to create is within the commented portions of the code …
Category: Web

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 from each post found? [ Object1 (ID, name, tag), Object2 (ID, name, tag), Object3 (ID, name, tag), etc. ] Thank you for your help afterwards! My code excerpt is here: $search_param = get_param('search_param', null, 'text'); // POST param $term_id = get_term_by('name', "$search_param", 'image_color')->term_id; $args = array( 'post_type' …
Category: Web

Query posts and display all dates in repeater field in chronological order

I have a Custom Post Type 'Production' with 'Tourdates' as a repeaterfield (using Advanced Custom Field plugin). Tourdates have a 'Date & Time Picker 'field named 'Playdate'. I would now like to display (in a list) all Playdates of all Productions sorted chronologically. My current query displays the posts like this: 09/04/2017 (Production x) 28/12/2017 (Production y) 07/04/2017 (Production x) 11/04/2017 (Production x) 31/04/2017 (Production y) 14/04/2017 (Production y) But I'm looking to get them displayed like this: 07/04/2017 (Production …
Category: Web

Sort query_terms_list for post_tags alphabetically

I have the following array that currently sorts tags by tag count and returns the tags with the individual tag count. I would like to keep the individual tag count but sort the tags alphabetically instead. I tried to change arsort( $list ) to sort ( $terms->name ) but I think my logic here is completely off. Any assistance is much appreciated :) Example: change from: oranges(20 )apples(12) bananas(10) to: apples(12) bananas(10) oranges(20) function get_query_terms_list( $taxonomy = 'post_tag', $sep = …
Category: Web

Display one random image from Media Library

I was asking if is possible to get all images from Media Library and display one of them randomly every time I refresh the page. I think it'd be something like make an array of media library images (php) and then just call one of them trying not to request unnecessary requests The think is I'm new in this world and I don't know how to start. Can anyone help me? Thanks!
Category: Web

Trouble with checked() for array of multiple checkboxes

I can't get the checked() to return what I expect. Data: Options: = array ( 'baseball' => 'Baseball', 'golf' => 'Golf', 'hockey' => 'Hockey', ) Values: = array ( 'baseball' => 'Baseball', 'golf' => '', 'hockey' => '', ) I'm using this code to try to return 'checked="checked"' foreach ( $options as $key => $title ) { rpq_plugin_debug_var( $key, 'Key: ' ); rpq_plugin_debug_var( $title, 'Title: ' ); $checked = checked((in_array($key, $values)), true, false); I'd expect the baseball option to return …
Category: Web

Include current post into loop

I have a related posts loop ( in every single post page ) based on post title. source : https://wpza.net/get-related-posts-based-on-the-posts-content-in-wordpress/ But I also need to include current post into this loop 'post__in' => $similar, . Please can anyone help me how can I do this function custom_related_posts() { $current_id = get_the_ID(); $current_content = get_the_title( $current_id ); $similar = array(); $scores = array(); $percentage = 0; $output = ''; function compare_content( $current_content, $comparison_content ) { $current_content = trim( strtolower( $current_content ) …
Category: Web

Populate dropdown with Child Pages based on Parent Page chosen

I'm trying to populate the Child Page dropdown with that of the selected Parent Page - If a specific Parent page is chosen it should fill the second dropdown with all Child pages listed under that parent. Once the submit button is clicked, it would then direct users to the selected child page. In the first dropdown, I've pulled the necessary Parent pages based on their page ids. I'm stuck from here. What do I do to achieve getting the …
Category: Web

Outputting an array of term meta values in a custom WooCommerce tab?

Forgive me – my Wordpress/PHP skills are hilariously rudimentary, so I may not use the correct terminology. I have added a custom tab to the WooCommerce single product page and need it to display a number (sometimes single, sometimes multiple) of term meta values related to a custom taxonomy, 'book-author'. These values are created in a WYSIWYG editor and contain HTML formatting. Each 'book-author' has an author bio (the term meta 'wpcf-author-biography'), and each WooCommerce product has one or more …
Category: Web

Custom archive page for custom taxonomy and pagination issue

so this is something I am trying to figure out for quite some time about my custom archive page for a custom taxonomy 'workplace'. There is many workplaces, and what i want is to display the products ( custom post type ) associated with the workplace by their categories, and also there descendents ( line 232 is an example of this. ) So for The 6 sections of categories, it finds each product category associated with each product and does …
Category: Web

List latest post for each tag with a category

I have a page where the latest posts are displayed from within a specific category. array( 'posts_per_page' => -1, 'post_status'=>"publish", 'post_type'=>"post", 'orderby'=>"post_date", 'order'=>'DESC', 'cat'=>"5" ) Within this I would like to only show the latest post for each tag. I don't know if this is possible but I'm hoping I'm wrong.
Category: Web

update_post_meta() updating nested array in Multidimensional array with empty sub-array

How can i update/remove/empty a sub-array on user post submission in admin area? here ist the reference on how to update nested array i am using but it is not working if ( $post->post_type == 'ds_product' ) { if ( isset( $_POST['meta'] ) ) { if ( !empty($_POST['meta']['ds_product_gallery']) ){ $gallery_data = []; for ($i = 0; $i < count( $_POST['meta']['ds_product_gallery']['picture'] ); $i++ ) { if ( !empty($_POST['meta']['ds_product_gallery']['picture'][ $i ])) { $gallery_data['picture'][ ] = $_POST['meta']['ds_product_gallery']['picture'][ $i ]; $gallery_data['figcaption'][ ] = $_POST['meta']['ds_product_gallery']['figcaption'][ …
Category: Web

Plugin settings page checkbox not saving - one options array with sub array

I'm driving myself crazy here trying to get a checkbox to save on a plugin settings page. Right now, as a template, I'm working through the excellent example given here: Settings API with arrays example I'm also referring to a very useful tutorial at https://www.smashingmagazine.com/2016/04/three-approaches-to-adding-configurable-fields-to-your-plugin/ with a detailed git at https://github.com/rayman813/smashing-custom-fields/blob/master/smashing-fields-approach-1/smashing-fields.php I've also read about a half dozen posts with similar questions but none have my answer, at least that I can find and understand. I think I'm stumbling on …
Category: Web

Combine 2 arrays in a query parameter

I'm trying to exclude upsells using post__not_in but I already have a value and do not know how to combine the two. I tried this: 'post__not_in' => get_upsell_ids(), [get_the_ID()] But it is not working. My code: function eligo_custom_related_products_by_label() { if (is_product() && has_term('records', 'product_cat')) { global $post; if ( ! $post ) { return; } $related_by_same_label = wp_get_post_terms($post->ID, 'pa_label', ['fields' => 'slugs']); $args = [ 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'rand', 'posts_per_page' => 4, 'post__not_in' => [get_the_ID()], …
Category: Web

How to write PHP array to render JSON-LD Markup for Job Postings, with ACF

i want to add a dynamic JSON-LD (schema.org) for career posts in my wordpress page. I tried this code below. But i think i have some Syntax errors within the array. Maybe the "echo" is not allowed within the array? I hope somebody can help me with this? <?php function schema() {?> <?php if( have_rows('schema_auszeichnung') ): ?> <?php while( have_rows('schema_auszeichnung') ): the_row(); // Get sub field values. $title = get_sub_field('title'); $description = get_sub_field('description'); $state = get_sub_field('state'); $date = get_sub_field('date'); $street …
Category: Web

How do I use foreach to get content from a custom-field in multiple posts?

so I am trying to use a foreach to pull content from a custom field in multiple posts, but it just wont work. I can get it to work for a simple textarea string but I am struggling getting it to work for arrays. This is the working code for a string: $posts = get_posts(array( 'numberposts' => -1, 'post_type' => 'post',)); foreach($posts as $post) { $string = get_post_meta($post->ID, 'simple_string', true); echo $string; } And elsewhere in the site this code …
Category: Web

Problem with inserting multiple images in gallery of each WooCommerce product programmatically

I am creating a script to programmatically add multiple images to the gallery of each WooCommerce product. The script works but only takes the first image, I'm having a hard time figuring out how to save each array containing gallery images then move on to the next one. Obviously I tried several times with the "for" loop but I always have errors. Here's the var dump of my code (Without Wordpress functions): array(2) { [0]=> string(47) "e8d753_4d28f4185e754761aaedee75b710f4b7~mv2.jpg" [1]=> string(47) "e8d753_2b34ab0d9ae84c84a50ea7a71e3b17b2~mv2.jpg" …
Category: Web

Get current user array with post string

I need to get 10 current user fields and pass the field values to a post string. The post string is expecting certain label names for each value. Example - post string expects 'firstname' => 'value', not 'user_firstname' => 'value'. After days of fatal parse errors for syntax, now I just get a fail status. Either my array code or post code, (or both), is somehow flawed. I read a post today from 2011 that says since WordPress 3.3 (current …
Category: Web

Insert woocommerce products programmatically with featured image and gallery

I'm inserting WooCommerce products programmatically to the database, but I'm having trouble inserting and linking first image as featured image and multiple images for gallery assigned respectively to each product from multiple URLs, Would you have any idea how to do it? <?php if(!empty($girls)) { $ops = array_map('str_getcsv', file(get_option('siteurl') . '/wp-content/uploads/2022/02/'. $girls)); $myres = array_map('array_filter', $ops); $ops2 = array_filter($myres); $items = array(); foreach($ops2 as $username) { $items[] = $username; } foreach ($items as $it) { $title = array_key_exists(2, $it) ? …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.