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
2answers
17 views

Static Page, need Last and Next links at the bottom

I am new here, I do not have a ton of experience with PHP but if I have a correct block I can work the different functions. I have a static page, currently, I have it set to display 5 snippets of ...
0
votes
0answers
16 views

Arrey by tag from edit page

i have very specific question, I need a option to add array from the editor edit page, i mean when you type text to page i need option to select tag and display all post with this tag. This is some a ...
0
votes
1answer
33 views

Ajax not sending the data correctly- Multidimensional array

I have a big multidimensional array being sent as ajax post. But in some servers, it does not send the data completely a portion at the end of the array is being cut out. Is there any limitations? ...
0
votes
0answers
19 views

Trying to merge these two arrays

This code below shows categories and tags associated with the posts. It works well BUT if there are no associated tags then it throws this error: Warning: Invalid argument supplied for foreach() ...
1
vote
0answers
25 views

How to Translate a string of an array inside a class?

I want to translate my functions.php with custom code in it. There I have a Class "Glbl_Helper" with a public static array that contains strings like "translate_me". Now I want to translate the ...
1
vote
0answers
21 views

How do I get create a custom table showing the hours remaining for all customers in one page from this transactions page?

[insert_php] global $wpdb; $current_user = wp_get_current_user(); $emailAddress = $current_user->user_email; /*$emailAddress = "samplethis@youguessedit.com";*/ [YADDA YADDA YADDA CODE] "; /* ...
0
votes
2answers
37 views

Loop over Array and get the distinct ids

I've made a loop that goes over all the gigs I've attended, some gigs have the same songs. Here is the result of that array: http://snippi.com/s/k80v7pe Now I want to have an array of all the ...
1
vote
1answer
30 views

How to pass conditional array to wp_localize_script

I'm trying to generate a custom array from a PHP function to pass on wp_localize_script but I seem to not be able to set page conditionals. I have the following function: function ...
0
votes
0answers
18 views

How to get ordered fields from repeateble fields group added via Toolset wordpress plugin?

I got 2 fields in group ordered by toolset-post-sortorder meta_key: youtube_id: TeBW-WByzlw 144 163 youtube_id: CEdYPEKDD2E 255 270 This it how it look in DB: This is how I try to get fields: $...
0
votes
1answer
13 views

Obtaining array item from WordPress revisions output

I am having trouble retrieving an array item from WordPress revisions array. I have Googled and no answer I have come across has worked so far. What I am trying to do is create a list of all Authors ...
0
votes
0answers
26 views

How to get Wordpress post filter (misha_filter_function) to filter CPT categories associated with a tag

I'm using the misha_filter_function from: https://rudrastyh.com/wordpress/ajax-post-filters.html to filter posts. The initial array is displaying the correct posts by the location_and_season (made ...
0
votes
1answer
19 views

ACF - Get ID of relationship field in flexible content

I'm trying to get ID from a relationship field within a flexible content and push it in a array if (have_rows('studio_blocs')) { while(have_rows('studio_blocs')) { the_row(); $...
0
votes
0answers
10 views

Accessing array elements WOOCOMMERCE API

I would really appreciate who can guide me with the following: I have the following ARRAY, it is a record of a product in woocommerce-wordpress that RETURNS three DIFFERENT variations: 1837, 1838 and ...
0
votes
0answers
23 views

WP_User_Query Orderby Not Working

If I use the following code, I can retrieve users in the correct order: $user_query = new WP_User_Query( array( 'role__in' => wp_parse_list( $atts['userrole'] ), 'meta_query' => ...
0
votes
1answer
29 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
0answers
17 views

Loop through an array and find the ID in another array

So I'm having some trouble with my looping and I would like to resolve it if possible. Below, I will go into detail on what I currently have: $test = strtoupper(str_replace(' ', '', trim($record->...
0
votes
1answer
24 views

How to create an array if 'empty'?

Sorry if this is super "newbie", but I'm stumped. I'm trying to create a function in WP All Import that states if the cell is empty it populates with "Not Specified". Please see below: function ...
0
votes
1answer
15 views

Link To Child Category For A Post

I'm trying to display a link to just the child category on a Wordpress post. For instance if the category for a post is parent > child I want to show a link to just the child category page. I'm using ...
0
votes
0answers
17 views

Display Specific Parent and Child Category Lists with Format

I have a code that I want to display in lists. <nav> <ul class="simplefilter filter-port"> <li class="btn active button btn-hover" data-filter="all">All</li> ...
0
votes
1answer
33 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 ...
0
votes
1answer
19 views

How to access or parse key/values that have “string”

Coming from a Perl background (no snickering) and trying to make sense of some new conventions. Not sure whether this is a PHP, WordPress, or Ninja forms question. $form_data //Ninja parlance ...
0
votes
1answer
20 views

If Array Values Match Another Array's Values, Then

I have a user drop-down field that includes High, Medium, or Low ranking. Each ranking has three requirements for evaluation types. I also have three additional drop-downs with options to choose ...
0
votes
0answers
66 views

Get user count based on multiple meta key values?

I am trying to count all of the users meeting multiple criteria. I have tried so many different things and cannot get it to work. Any help is much appreciated. Thank you. add_shortcode('...
0
votes
1answer
16 views

Ordering of posts, 2020 Year showing as next event when should be last

We have some event posted into wordpress which are ordered by date. All works well except when we enter an event for 2020 it comes at the top of the list rather than the bottom. The date is save in ...
0
votes
1answer
21 views

Loop through array of pages

I am trying to recursively get all children of a page (infinite depth) and I am using function below, from this solution: function get_all_subpages($page, $args = '', $output = OBJECT) { if (! ...
0
votes
1answer
71 views

List a maximum of ‘x’ product categories with qty of ‘y’ in each column

Im trying to list a maximum of ‘x’ product categories (a multiple of y) with a qty of ‘y’ in each column. ‘x’ decides how many columns are displayed. What I am trying to do: - If there are less ...
0
votes
1answer
372 views

Display WooCommerce product categories in a 4 columns custom menu [closed]

I'm trying to list a set amount of product categories (x) in a dropdown menu, but if the total amount of product categories are greater than x then only list x minus 1 and display “view all categories”...
2
votes
1answer
45 views

merging an array to an existing array using add_filter

I'm working on a plugin and i want to be able to extend some of the functionality using apply_filters(). I have a setup like this which is the default values; print_r( apply_filters( '...
0
votes
1answer
17 views

Remove empty terms from array, sort alphabetically, update back to repeating field

I have a repeating field that stores text terms in an array, like this: [0] => [1] => NUC Lights [2] => Smoke Alarm [3] => Binoculars You'll note key A has no value, and they're not ...
0
votes
0answers
23 views

Pass an argument into a function to extract from array

I feel like this should be possible. I have a function within my class which pulls a single row from my custom table: class Get_Data{ public static function get_data_single_db() { ...
0
votes
0answers
15 views

How to make this custom capability work? [duplicate]

I am trying to make a custom ability on my page CV people can insert and then view their CV I made a custom capability view_cv and I want for it to remove the option to view their CV. <a class="...
0
votes
0answers
16 views

Get all the Tags Assigned to Current User

I am looking to find a way to get all the user_tags. I have 3 Tags applied to the current logged in user I just want to simply get the tags as an array. Something like this: $user_tag = array('29GA ...
0
votes
2answers
31 views

adding additional class to get the post thumbnail [duplicate]

I'm just starting to create new theme and i'm new to code. I'm stuck in customizing the post thumbnail code, i tried add <?php previous_post_link(get_the_post_thumbnail(get_previous_post(), array(...
0
votes
0answers
82 views

Array merging multiple get_posts throwing Undefined offset error

Good morning. I've been trying to create a related posts function. The broad idea being; the user can manually select related posts using an ACF relationship drag and drop interface, but if they don't ...
0
votes
1answer
57 views

Replace an array (with identical values) with another array in the_content

I'm making a plugin where I need to edit the H2 tags in the post content. I've been at it for two days, but my php knowledge is too limited to solve the issue.. What I want to achieve is to return ...
0
votes
0answers
10 views

show just subcategory array

Looking to see if I can modify the below coding to pull just the category information. Currently at the category level it will pull all the products. Is it possible to just pull the subcategories ...
0
votes
1answer
27 views

WordPress loop by meta key that is an array? and how loop multiple arrays

How can I get loop of posts by meta values that save in a meta_key that is an array like that $sharedHosting_plans_fields = Array ( ...
0
votes
0answers
15 views

Show the subcategory name based on current product

Hi I can display subcategory name in current product page (single product page) but it showed all the subcategory name. I just want to show subcategory name based on the product selected. I have one ...
0
votes
1answer
37 views

Updata Metadata WP Rest API

I am trying to update a metadata I created from the front-end with a click event. { "id": 1248, . . . "metadata": { "wishlist_array": [ "" ], . . . ...
2
votes
2answers
116 views

array_map() for sanitizing $_POST

I am working on an options panel for a plugin. And have an array being posted and updated to the options table. I am using the array_map() function to iterate over the array with sanitize_text_fields()...
0
votes
1answer
21 views

How to get user ID's from multiple usernames?

I am trying to produce user ID's from multiple specific usernames. The usernames are pulled from a profile field, and any number of usernames will be called. I want the user ID's from each of the ...
-1
votes
1answer
42 views

How to check if the postID is in an array? [closed]

In Wordpress, I am trying to check through an if else statement if the post is of a certain ID as follows: <?php if ($post->ID == array(224,222,583,645,203,11,639,228,226,230,634,615,625,214,...
0
votes
1answer
116 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 ...
0
votes
1answer
601 views

Only show first image in foreach loop

My loop shows a list of values, and underneath them, the post title and image for the value. The problem is that because some values are associated with multiple posts, multiple images show up. I ...
0
votes
1answer
44 views

Array ids post to function have_post

I get as result of a main sql an array of post IDs, now what I need that Array of ids post to obtain the information and be presented in the following way: <?php $ids = [1,2,3,4,5]; // ...
-1
votes
1answer
28 views

Create heirachy of post terms from array & assign post to terms

I have a text string called $location_string which is an address in this format: 1 Victoria Street, Wellington, New Zealand as well as a custom hierarchical taxonomy called location. I am trying to ...
0
votes
1answer
168 views

Conditional multidimensional arrays and array_map

I'm using Roots Sage 9, which uses Laravel within WordPress, and am combining this with Advanced Custom Fields. For this, I have created a Controller, where I use an array_map to iterate through the ...
0
votes
0answers
26 views

AJAX call recieving a 400 bad request when array lenght is to long

I have a select dropdown where users can choose multiple options that get's sent to a custom Rest-API endpoint and returns values based on their selection(s). The dropdown is dynamically populated ...
1
vote
2answers
33 views

Only a part of array is stored in transient – what could be causing this?

I have created an autosuggest array that I want to store in a transient. My code looks like this: <?php // Get any existing copy of our transient data $suggest = get_transient('suggest'); if ( ...
0
votes
1answer
34 views

Add to array, redirect and display

I want add text to array and display after redirect and unset array. class test{ public function one(){ $this->save(2, 'some'); $url = get_site_url(null, '/redirect_to_two');...