Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [array]

An array (in PHP) is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.

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

Orderby meta _value that is saved as an array

I want to order a WP_User_Query by a meta value. The meta key is a multi-select field, and the value is saved as an array. When I do a print_r of get_user_meta($user_id,'committee',true) this is what ...
0 votes
1 answer
705 views

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 ...
0 votes
1 answer
31 views

Send emails to individual subscribers when CPT post is deleted (trashed)

The context On my site I have a custom post type (project) where visitors can subscribe to a post and get various notifications via email. My site is hosted locally right now and I am using Mailhog ...
5 votes
4 answers
3k views

How do I pass an array as an argument to a WP-CLI command?

I want to use WP-CLI to create some new posts with custom taxonomy terms assigned. The challenge is that wp_insert_post's tax_input argument only accepts arrays, which I would have to specify on the ...
0 votes
1 answer
801 views

Custom WordPress Function - Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)

I've searched far and wide for a solution to the problem. I'm almost there, but can't seem to get it working completely. Background There are 3 post types that are involved in this function: League, ...
0 votes
1 answer
25 views

Is there a way to use MySQL JSON functions in meta queries?

There are JSON functions: https://dev.mysql.com/doc/refman/8.3/en/json-search-functions.html can be used to search in complex data with MySQL. In the case of meta keys and values it is an issue that ...
0 votes
1 answer
724 views

update_post_meta adding to array instead of replacing value

update_post_meta() keeps adding to an array instead of replacing value. Any tips? Previously I used add_post_meta() by accident and perhaps that somehow flagged the field as an array? Update So how ...
2 votes
2 answers
806 views

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 ...
1 vote
1 answer
1k views

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 ...
0 votes
1 answer
1k views

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' => '...
1 vote
1 answer
7 views

Get check box values inside array for use in posting form data

So I have the following function with an array of variables that handles a profile form. All but one is a typical input with the exception of 'member-comptency[]'. It's a select field field with ...
0 votes
1 answer
1k views

how to remove/exclude html coding from json file while export?

I have created a file using json and exported it. Its creating HTML tags with it. Actually,I don't want to have that html part to be there in the file. Below I am sharing structure of my current file: ...
0 votes
1 answer
1k views

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 ...
0 votes
1 answer
2k views

Wordpress meta query with meta serialized data array value

Looking for a method to nest AND/OR relation in meta_query based on array serialized values. Reviewed these already: Query multiple meta key values? WP Meta Query for some meta (array) values I ...
6 votes
4 answers
13k views

Reversing the order of posts AFTER the query is performed

I'm am displaying the last 5 posts of a custom post type 'show'. This gives me the latest post first. <?php $args = array( 'post_type' => 'show', 'posts_per_page' => 5, 'order' =...
0 votes
1 answer
734 views

wp_insert_post($post), add an array of values with update_post_meta

i try to store an array in multiple custom fields via post creation (wp_insert_post). The array is $event_test and the key is event_test on the meta_input. On form submit, the custom field is shown, ...
0 votes
1 answer
996 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
1 answer
31 views

Parameter for pagination posts_pagination

I created a pagination with the_posts_pagination() function Right now it looks like this and it works fine: Previous 1 2 3 4 Next When I am on the 1st page, the "prev" button disappears or &...
0 votes
2 answers
1k views

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 (...
0 votes
1 answer
676 views

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' => '...
0 votes
1 answer
31 views

generate an array of user login date using update_user_meta();

I have begun to create a function to store last login date of user using time() function. Perfectly works! Now I want to store in a serialize array a list of all user login date. Question : Do I have ...
0 votes
1 answer
191 views

posts_results filter - additional sort, with a meta value, to move posts to the end of the results, with pagination working

I have a custom post type for business locations that I am trying to add an additional sorting filter to by using a custom meta value. The custom field specifies whether or not the location is open or ...
0 votes
1 answer
693 views

Make sticky post with FacetWP

I have WordPress posts in combination with Advanced Custom Fields and FacetWP for filtering. WordPress has an option to make a post sticky, I did this and nothing happenend so I tried to change my ...
0 votes
0 answers
28 views

How to pass php array to external js file in WordPress

I am trying to pass my php array to my external js file. PHP if (!function_exists('myScripts')) { function myScripts() { wp_enqueue_style('my-css', get_stylesheet_directory_uri() . '/...
0 votes
0 answers
37 views

Array_splice index problem in ACF Flexible Content

I want to insert a row layout from an ACF Flexible Content field in one page (templates page) into the Flexible Content that is assigned to another page (Original). The Flexible Content field group is ...
0 votes
0 answers
12 views

Query for posts belonging to multiple categories

Within the default Post categories I have A parent category Cities -- City A -- City B -- City C A parent category Beauty -- Hairdressers -- Pedicure A parent category Sightseeing -- Archeological -...
1 vote
1 answer
688 views

How can I make my options in an array and store theme in WP options one DB row?

I am making a theme with theme options but for customization, I have completed my theme options more than half. Suddenly I have triggered one problem and that is I have checked my wp_options DB I have ...
0 votes
0 answers
123 views

Loop through Redux option framework repeater field

I am using Repeater field of Redux Framework in WordPress. I have created the repeater field and assigned the data. Now I am trying to display those data in front end. But I am not getting how can I ...
1 vote
0 answers
22 views

post__in select all custom posts and not the selected array of ids

In order to add a personilized sidebar for costom posts I define a shortcode using add_shortcode ( >name shortcode< ) and I recall the shortcode in sidebar using a plugin. In the sidebar I must ...
0 votes
1 answer
16 views

PHP - Converting elements to actual values

I made a list of checkboxes that upon click would be sent to database. Every time I submit data the value is 0. If I try and convert the value of the array to string, I get string to array error. <...
9 votes
4 answers
43k views

Order by & include array by specific post ids

I have the following: <?php $num_cols = 2; // set the number of columns here $args = array( 'post_type' => 'testimonials', 'posts_per_page' ...
0 votes
1 answer
32 views

wp_query, calculate with two dates when 'key' is text format

I have the custom field "members_entry" which is the key and it is in text format (not in date format!). I cannot change the format of the custom field in WP, it has to be text. I have the ...
1 vote
1 answer
81 views

Display custom post type attached media file sizes

We have a custom post type slugged 'download' and it acts like a posts but with the different slug. (It displays content like a post). Now, We have a custom field named "videos" and ...
-1 votes
1 answer
66 views

Adding date and time to the same request

I would like to call the get_the_date and get_the_time in the same request. Is this possible? This what I'm doing now. <?php $header = array( //Home "15" => array( &...
0 votes
1 answer
872 views

How to group by column a and sum column b and c in a php array

I got the following array: [0] => Array ( [kanel] => 5 [peber] => 0 [shipping] => A ) [1] => Array ( [kanel] => 25 [peber] => ...
1 vote
0 answers
153 views

Replace block content with an array

I'm using GenerateBlocks and Metabox, and specifically relevant for this post, MB Relationships. I have a query loop created with GenerateBlocks that displays a list of Events (CPT). I have another ...
0 votes
1 answer
25 views

How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?

I have a CPT with daily deals, I need to show these daily deals on my frontend as per today's day. For eg, if it is Thursday : The returning array should return Thursday, Friday, Saturday, Sunday, ...
0 votes
2 answers
3k views

return an array with a shortcode

i have some fields, which i would like to print out with an shortcode with one attribute. i have normal variables and arrays, with my code only the first value of an array is printed... should i use ...
-1 votes
2 answers
3k views

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 ...
0 votes
0 answers
37 views

Custom fields: Split data from single custom field's sub-array to separate custom fields when saving post

TLDR; I’m using a plugin that stores its custom field data in a sub-array, and I would like to save parts of the data from the sub-array to separate custom fields when a post gets saved. In my case, ...
0 votes
0 answers
154 views

save array of objects with update_option

How do I save an array of objects in Wordpress/PHP via update_option ? What I'm trying to save is something like: update_option('my_option', [ { 'c': htmlspecialchars($_POST['hidden_category']), ...
0 votes
0 answers
43 views

How do I have multiple metaqueries inside one wordpress query

I have a parent->child relationship between artists and releases. There is another parent->child relationship between releases and versions aka albums, singles, videos, misc. So artist is the ...
0 votes
1 answer
491 views

How to get files from loop for zip

I am working on a button which will download the images as a zip on specific posts. It works if I leave the files array in functions.php with a few hard-coded img links. But when I move the array to ...
0 votes
1 answer
72 views

Why is my array_diff usage breaking things?

On my WordPress site, I usually only have one tag per post. However, I now have some posts that have a second tag, "expired", that I use for another purpose. So I need to adjust my code ...
0 votes
1 answer
13 views

WordPress emails error regarding the argument type even if the type is correct

function test_sort_terms_hierarchicaly( Array &$cats, Array &$into, $parentId = 0 ) { if ( is_array( $cats ) ) { foreach ( $cats as $i => $cat ) { ...
2 votes
2 answers
10k views

How to save array of datas in option page by setting api?

I am trying to create my own first plugin but I am coding novice so please guide me to the right direction. This plugin is to set the post expiry date based on the user's role. Now I am stuck at ...
0 votes
1 answer
170 views

Multipe array in meta_input

I want to insert post with wp_insert_post and add meta_input in it. I have to send my data with array but I have problem to send more than one Here is my code : wp_insert_post( array( ...
0 votes
1 answer
867 views

get_body_params() is always empty in POST request

I am registering a custom route like this : add_action('rest_api_init', function () { register_rest_route( 'professeurEQ', 'statistics', array( 'methods' => 'POST', 'callback'...
0 votes
1 answer
33 views

Order Categories by Character Count

I'm developing a medical directory website in Wordpress, and in the Grid/List pages for the site, each of the listing cards contains a list of specialties (using the category taxonomy within the ...
0 votes
1 answer
586 views

How to echo the value of an array element using a function via a shortcode

I want to centralise the prices on our website, so that I can simply update one place, and once updated it propagates to all pages. I don't want to use a plugin. The idea I have is to create an array ...

1
2 3 4 5
16