Skip to main content

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
25 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 ...
LBF's user avatar
  • 529
0 votes
1 answer
33 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 ...
dekkyd's user avatar
  • 7
0 votes
1 answer
27 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 ...
inf3rno's user avatar
  • 135
1 vote
1 answer
8 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 ...
visyoual's user avatar
  • 111
0 votes
1 answer
32 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 &...
Thica's user avatar
  • 17
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 ...
imagIne's user avatar
  • 83
0 votes
1 answer
204 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 ...
user13286's user avatar
  • 255
0 votes
0 answers
32 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() . '/...
DigitalDesigner's user avatar
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 ...
Horizzons's user avatar
0 votes
0 answers
13 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 -...
Brecht Schoeters's user avatar
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 ...
Gianluigi's user avatar
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. <...
Jdubstep2345's user avatar
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 ...
MauLox's user avatar
  • 1
1 vote
1 answer
87 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 ...
user14772091's user avatar
-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( &...
Richard's user avatar
0 votes
1 answer
909 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] => ...
Jannickla's user avatar
1 vote
0 answers
161 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 ...
nomade0's user avatar
  • 27
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, ...
Advait Nandeshwar's user avatar
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, ...
physalis's user avatar
  • 310
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']), ...
Nathan Bernard's user avatar
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 ...
DJZEEGLER's user avatar
  • 119
0 votes
1 answer
505 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 ...
Ben Blue's user avatar
  • 117
0 votes
1 answer
76 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 ...
Chris's user avatar
  • 105
0 votes
1 answer
15 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 ) { ...
brittle_spirit's user avatar
0 votes
1 answer
181 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( ...
Mehran Pourjenabi's user avatar
0 votes
1 answer
810 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, ...
chris's user avatar
  • 3
0 votes
1 answer
900 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'...
Valenten's user avatar
0 votes
1 answer
35 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 ...
Versace's user avatar
0 votes
1 answer
601 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 ...
wickyd's user avatar
  • 103
0 votes
1 answer
36 views

Update value inside array update_post_meta

I am trying to change default values inside array in custom field. But I am getting error "PHP Fatal error: Uncaught Error: Cannot use string offset as an array" when I try to change the ...
user7459842's user avatar
0 votes
1 answer
276 views

Array_search ignoring the first element [closed]

I made (copy) a function to make the url of the custom post (named investigacion) by year. function tex_get_archives($post_type = 'investigacion') { global $wpdb; $query2 = "...
Daniel Leandro's user avatar
0 votes
1 answer
441 views

Check if user has comment on current post

Hello I have multiauthor website and I need to create a condition to check if defined user ( no current user ) has comment on current post. Here is my code but I can not complete this $userid = "...
Teymur Abbasov's user avatar
1 vote
1 answer
62 views

Remove Body Classes

I need to remove specific body classes added as a comma separated delimited list to a custom field input field like this wp-custom-logo, single-post, postid-28, single-format-standard, logged-in, ...
Brad Dalton's user avatar
  • 6,926
0 votes
0 answers
188 views

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> &...
Peanuts's user avatar
  • 125
0 votes
1 answer
110 views

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 ...
Teymur Abbasov's user avatar
1 vote
0 answers
80 views

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 ...
ZUH.'s user avatar
  • 11
0 votes
1 answer
297 views

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 (...
mir's user avatar
  • 16
0 votes
1 answer
81 views

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 == '...
Gildas.Tambo's user avatar
0 votes
1 answer
17 views

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&...
Gareth Roberts's user avatar
0 votes
1 answer
195 views

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 ...
Ioannis Koukotzilas's user avatar
1 vote
0 answers
2k views

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 ...
Archer's user avatar
  • 11
0 votes
0 answers
220 views

Save / Update meta data as multidimensional array

I need some help with saving my meta data from a post. On the editpage I have the following input fields <input type="text" name="data[color][]" value="red"/> <...
Liekeee's user avatar
0 votes
2 answers
210 views

How to get the `comment_post_ID`?

I have extracted the reply emails. The original emails are saved as CPT and work as Tickets in my plugin. I want the reply email to go as a comment to the original email. for($j = 1; $j <= $total; ...
Rohit kc's user avatar
0 votes
1 answer
209 views

get_the_terms, whether I should use string or array as the second parameter?

When I running Query Monitor on one of my page, I get a notice "Array to string conversion" for the following line: $terms = get_the_terms( $post->ID , array( 'product-categories') )...
alancc's user avatar
  • 41
0 votes
1 answer
159 views

last_name + first_name orderby with meta_query [solved]

I have small issue with orderby. I´m looking solution to orderby ASC (lastname + firstname) example: Selanne Andy Selanne Beeny Selanne Teemu But now it arrays something like this: Selanne Beeny ...
MSI's user avatar
  • 3
0 votes
1 answer
33 views

How to get the last category name of a child category?

there. I've tried tons of solutions I've found in this forum before asking this. It's kind of hard for me to understand the php sintaxe. I have no idea how to do this and i've been stuck for days ...
Jay's user avatar
  • 11
1 vote
1 answer
22 views

Sorting table function default

Trying to get this table to sort by default by "publish_date" Where can I add it? $transaction_params = array( 'posts_per_page' => $page_size, ...
Caroline's user avatar
0 votes
0 answers
100 views

Sending simple variable on single page to WP JSON

I like to send specific data from a post to my JSON response in Wordpress. I like to send the output of the variable "hatus" to the JSON response, but it does not seem to work. <?php ...
Johan's user avatar
  • 309
0 votes
1 answer
46 views

meta_query compare “=“ returns nothing when it seems it should

Trying to query based on form submission. One select on the form is built with: wp_dropdown_categories( 'name=specialty&taxonomy=specialties&orderby=name&show_option_none=Select a ...
dgl's user avatar
  • 1
0 votes
2 answers
801 views

Tax query with multiple terms in pre_get_posts

I am trying to use a tax query in my pre_get_posts function. All is working but not when the array has multiple IDs. Let's say my URL looks like: ?listing_cat[]=1&listing_cat[]=2 Now I am trying ...
RobbTe's user avatar
  • 242

1
2 3 4 5
16