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
1answer
11 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 => $...
0
votes
0answers
16 views

MYSQL: only seem to be able add one category instead of array

I want to add posts to category called "New York" (ID 88) and also to category "USA" (ID 89) based on regex, I cannot seem to get it to add to both at once. Managed to get it working just for one. ...
0
votes
2answers
22 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 (...
0
votes
0answers
8 views

wordpress output numbers from an array of checkboxes

I'm not a php expert at all, but I've just started to learn it. I'm using a function on wordpress which creates a xml file after pressing send button on a contact form (with contact form 7). That's my ...
0
votes
1answer
87 views

How to use if statement in an array? [closed]

Firstly sorry for my English. I hope you understand me. I have an array like this: $fields = array( 'author' => '<div class="form-group"><input class="form-control" id="author" name="...
0
votes
0answers
39 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 ...
0
votes
0answers
12 views

Display related posts based on matching the category and a tag within a custom taxonomy group

Hi community and thanks in advance. My aim, I simply want to display Pubs/Bars related by the same area tag, automatically, on every post. I found and followed what looked like an excellent solution ...
1
vote
1answer
39 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 ...
0
votes
1answer
850 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
1answer
16 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 ...
0
votes
1answer
21 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
1answer
25 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 ...
0
votes
0answers
15 views

Foreach inside args array to get categories IDs

Please help me write this code correctly to get the category Ids, one, and more with comma-separated. <?php $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 5,...
0
votes
0answers
13 views

PHP - AJAX - field group array POST value always says undefined index

I have a group of two clonable fields name and email. So when user clones, they will have a set of name and email fields. Note: These fields are newly added to my code and AJAX was working fine with ...
0
votes
1answer
12 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') ); ?> ...
0
votes
1answer
727 views

Remove duplicates - array_unique()

I am trying to make a simple list of names that link to profile information. Some of the people in the list have multiple addresses and therefore appear multiple times in the list (as their addresses ...
0
votes
1answer
23 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] => ...
0
votes
0answers
26 views

Parse array to string , and get value to show in html

I made some changes on a plugin that return me an array with multiple vaues and array inside. I tryed to get the value of array to display in a table, but i don't found the right way to do this. This ...
0
votes
0answers
20 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: ...
1
vote
0answers
25 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 ...
0
votes
1answer
848 views

How can get all users by current user meta?

I have a block system to make users block each other, My question is how to get all users by current user meta by the array? When current user is blocked anther user it's saved as meta like this: a:1:...
0
votes
1answer
33 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 ...
0
votes
1answer
17 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 ...
0
votes
1answer
457 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
0answers
24 views

Hide shipping method only for specific Woocommerce product categories

I tryed the following code, but it wouldnt take my categories but hides flat rate all of my products: add_action( 'woocommerce_package_rates','show_hide_local_pickup_shipping_methods', 10, 2 ); ...
0
votes
1answer
3k views

Plugin error “array_key_exists(): The first argument should be either a string or an integer” [closed]

Checking the Query Monitor, it's throwing out this error, array_key_exists(): The first argument should be either a string or an integer which relates to this function: public function ...
0
votes
0answers
12 views

how to exclude specific pages form wordpress search results?

I want to show only today's events and the next events in Worpdress search results for every post with category "events". This is my code and it doesn't work, the events that have ended still appear ...
0
votes
1answer
523 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' => '...
1
vote
1answer
23 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 ...
1
vote
1answer
719 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
1answer
25 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'=&...
0
votes
0answers
14 views

Multi select plugin options: Only one value is saved [duplicate]

At the moment I'm stuck with a multi select option for my plugin. I took one of my working select callbacks and added multiple="multiple" to it. Doesen't matter what I'm selecting only the option ...
0
votes
2answers
2k 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 ...
1
vote
1answer
23 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']; ...
0
votes
1answer
734 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
0answers
23 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 ...
1
vote
0answers
10 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 ...
0
votes
1answer
768 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
2answers
26 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 ...
0
votes
2answers
26 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
2answers
3k views

how to limit and display tag?

Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any 3 tags randomly. for eg: A sample post <a href="/tag1">Tag1</a> &...
0
votes
1answer
57 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
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
0answers
22 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
36 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
27 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] "; /* ...
1
vote
0answers
169 views

call_user_func_array() error in class-wp-hook.php

I have this message when I try to add a new variation of a product on Woocommerce/WP: Warning: call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two ...
0
votes
2answers
137 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
59 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
29 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: $...

1
2 3 4 5
14