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
313 views

Why are array_slice() and array_chunk() not working?

I'm trying to build a nav out of an array of child pages from a custom post type called "section" with a parameter depth of 1. I want to slice this array so that it only displays a part of ...
bfoley_teamug's user avatar
0 votes
1 answer
318 views

How to get an array with all categories and corresponding names?

I want to create a selector control in the Wordpress customizer with all the existing categories and for that I need an array with all the categories and their names. I need to get an array like this: ...
ralphjsmit's user avatar
0 votes
1 answer
58 views

Retrieve array items without page ID

I am using wp_list_pages to display our website's navigation. The nav is supposed to be 2nd level pages only. I want the nav to display the array's first four items and then nest the rest of the items ...
bfoley_teamug's user avatar
1 vote
3 answers
2k views

How to convert objects into arrays

Please i need assistance in converting objects that is returned from $wpdb->get_results into arrays so that i can call them values like $query['username'] instead of using $Query->username because ...
pandglobal's user avatar
0 votes
1 answer
129 views

add_post_meta add latest data from meta_value array

I want to add list of color to a product attribute with following code: function wcproduct_set_attributes($post_id, $_attributes) { $i = 0; foreach ($_attributes as $name => $...
Web Design's user avatar
0 votes
2 answers
6k views

How to insert multiple rows and columns in database using array

Please i want to know if it is posible to use one sql query to insert into multiple columns and rows using array in php $sql = "INSERT INTO MyGuests (firstname, lastname, email) <br> VALUES (...
pandglobal's user avatar
0 votes
0 answers
48 views

WordPress Settings API Overrides My Previous Value

I have created the following custom menu page to save some data, I've included some repeatable fields inside the form. The problem that I have is that every time I click the submit button it overrides ...
trunks's user avatar
  • 13
0 votes
1 answer
55 views

How to change category id on get_posts array

I am making a carousel for my AMP page, and I want to re-use the code, so I made it into a template, however, I am having the problem with changing ID on the array for category value, I would like to ...
AcidBurn's user avatar
0 votes
1 answer
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 (...
Newbie's user avatar
  • 1
0 votes
1 answer
30 views

Integer in Array returns null

Im using EDD_Fees class for adding extra fee to products, Iv’e used this class before and it works like charm but now i can’t figure it out why amount equals to 0 (it seems returning null) But when i ...
TheXrion's user avatar
0 votes
1 answer
48 views

Array for Wordpress Avatar Size and Class

I tried to set size and class for wordpress avatar in comments but I couldnt. <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, array('class' => 'media-object') ); ?> ...
I dont believe you's user avatar
0 votes
1 answer
179 views

How to order users by a date in the meta_value array

I have an 'payments' meta_key for the users. I store the payment information (date and payment amount) received from the user in meta_value connected to this meta_key. For example: array( [0] => ...
Faruk's user avatar
  • 25
0 votes
0 answers
465 views

How do i fix this "call_user_func_array()" error

Please, somebody, help me out.. How do I fix this? I kept on receiving this each time I tried to register an account and create a subsite on the frontend of my WordPress multisite Warning: ...
Theophilus's user avatar
1 vote
0 answers
31 views

Reprinting <img> tags with all attributes

I'm reworking a WordPress plugin that I've made which specifies image dimensions that are missing width and/or height attributes. As you can see in my current version on GitHub, I manually list all ...
Ethan O'Sullivan's user avatar
1 vote
1 answer
101 views

Create a post in custom post type using field in registration form after users submit form

As part of this project i have already created an Institute custom post type which i can see in the admin dashboard. What i want to do now is link it to the registration form. The logic is that when ...
junior's user avatar
  • 21
0 votes
1 answer
113 views

How to display MySQL table data which is stored as an array?

I have the table "mlw_results" which stores results of quizzes on my WordPress website. I use "Quiz And Survey Master" plugin to create these quizzes. Now I need to display all the results of a ...
user185668's user avatar
0 votes
1 answer
25 views

How can I get the content of the current page in my loop while merging post-type

I made a loop which is loading post-type. But while it is loading basic post and post-type, it is not loading the main content of the page. I am searching for a way to load the current page content ...
Yagayente's user avatar
  • 101
1 vote
1 answer
205 views

How to manage arrays from custom functions stored in functions.php?

In functions.php I have made the following code: add_action( 'listofnames', 'SomeNames' ); function SomeNames(){ $names=array( "john","edgar","miles"); return $names; } It should return array I ...
Bunny Davis's user avatar
0 votes
1 answer
663 views

get_users with array as meta_value

My WordPress users have a custom birthday meta key (DD/MM/AAAA, e.g. 25/02/2020). If I want to get all users born today (25/02) I can use: $todays_birthday='25/02/'; get_users(array('meta_compare'=&...
otpabu's user avatar
  • 1
1 vote
1 answer
113 views

sanitize POST arrays

I'm trying to sanitize some arrays received through $_POST[] and insert them into database. How should I do that? The html is name="room_types[]" $room_types = $_POST['room_types']; ...
dragos.nicolae's user avatar
1 vote
0 answers
39 views

Weird orderby => post__in issue

I seem to have run into a sort of odd issue with WP_Query post__in I can't quite figure out. ANY help is appreciated! Goal/Progress so far: Overall I want to merge two arrays and use the merged ...
RedBeard's user avatar
1 vote
0 answers
18 views

Compare with WP Meta Query

I've a situation with WP Meta Query. $args_1 = array( 'status' => 'active', 'number' => 'all', 'object_id' => array(2) ); I want to compare two 'object_id' in ...
Sam Loyer's user avatar
0 votes
2 answers
72 views

What code to use in an array to call the current sub-category?

On a page like taxonomy-product_cat.php - this function lists just the products for the called sub-category - bags: $args = array( 'post_type' => 'product', 'product_cat' => 'bags') $loop = new ...
Jon's user avatar
  • 366
0 votes
2 answers
36 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 ...
Jose Torres-Vega's user avatar
0 votes
1 answer
1k 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? ...
user avatar
1 vote
0 answers
172 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 ...
Programming Farmer's user avatar
1 vote
0 answers
73 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] "; /* ...
Flamingo RoRo's user avatar
0 votes
2 answers
1k 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 ...
Dennis's user avatar
  • 135
1 vote
1 answer
524 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 ...
markb's user avatar
  • 299
0 votes
1 answer
38 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 ...
Sam's user avatar
  • 367
0 votes
1 answer
1k 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(); $...
Jandon's user avatar
  • 147
0 votes
0 answers
148 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' => ...
Michael's user avatar
  • 281
0 votes
1 answer
689 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, ...
LovinQuaQua's user avatar
0 votes
1 answer
49 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 ...
Chad H's user avatar
  • 1
0 votes
1 answer
72 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 ...
Tnace's user avatar
  • 17
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 ...
LovinQuaQua's user avatar
0 votes
1 answer
150 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 ...
breadwild's user avatar
  • 189
0 votes
1 answer
115 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 ...
Michael's user avatar
  • 281
0 votes
0 answers
521 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('...
Michael's user avatar
  • 281
0 votes
1 answer
25 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 ...
Tom Mills's user avatar
0 votes
1 answer
284 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 (! ...
GeorgeP's user avatar
  • 317
0 votes
1 answer
100 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 ...
aye cee's user avatar
  • 159
1 vote
1 answer
2k 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”...
aye cee's user avatar
  • 159
2 votes
1 answer
873 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( '...
Kolawole Emmanuel Izzy's user avatar
0 votes
1 answer
27 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 ...
warm__tape's user avatar
0 votes
0 answers
34 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() { ...
Shaun21uk's user avatar
0 votes
0 answers
18 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="...
Renārs Abeļūns's user avatar
0 votes
2 answers
454 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(...
haiz85's user avatar
  • 11
0 votes
0 answers
256 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 ...
morgyface's user avatar
  • 103
0 votes
1 answer
227 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 ...
Erick Arends's user avatar

1 2
3
4 5
16