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
0answers
7 views

Get only one array instead of multiple arrays with PHP

I'm trying to build one json object out of one array, but my loop seems to be building several arrays. This is what I'm getting: [{"basic_lease":"5209"},{"expanded_lease":...
0
votes
1answer
13 views

How to write PHP array to render JSON-LD Markup for Job Postings, with ACF

i want to add a dynamic JSON-LD (schema.org) for career posts in my wordpress page. I tried this code below. But i think i have some Syntax errors within the array. Maybe the "echo" is not ...
0
votes
1answer
20 views

how to separate an array into different arrays and save them into db?

I have a quick question, I'm developing a wordpress plugin and need some help I have the following array which I got in php from ajax: $array = [ "car_model_1=modelo 1", "...
1
vote
0answers
21 views

Display a CPT based on a metabox selection

I am trying to display multiple post based off a custom metabox selection. I am currently using CMB2 as my framework to display the CMB within the backend. The selection field which has an ID of ...
0
votes
1answer
37 views

What form should the $query media query array have for an Elementor page builder function? [closed]

I'm building a theme with the Elementor page builder and I want to add some CSS output to certain elements. I hooked into the parse_css function. I want to use the stylesheet::add_rules() function (...
0
votes
1answer
21 views

Adding an item to an anonymous array inside a filter?

I'm trying to add a user_role inside the ATUM stock management plugin. Currently it's only visible to admins, while I also want to add shop_managers. But I just can't succeed in adding it successfully ...
0
votes
1answer
30 views

Save data from a checkbox to a wpdb array

I have several fruit checkboxes but when saving to the wpdb database it only saves the last one that it checks, variable $check receives vardump string (6) "banana" string (5) "apple&...
0
votes
1answer
10 views

How can I display Only the first Array/Object?

By using Wordpress REST Api ./wp/v2/users/?_fields=id&orderby=id&order=desc Result [{"id":13},{"id":12},{"id":11},{"id":10},{"id":9},{"...
0
votes
1answer
30 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 ...
0
votes
1answer
24 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: ...
0
votes
1answer
47 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 ...
0
votes
0answers
4 views

How to add multiple users (values) to array

I'm blocking the 'editor' role from Elementor Menu items by referencing this thread: Remove Elementor Menu From Wordpress Admin function remove_menus(){ // get current login user's role $roles = ...
0
votes
3answers
68 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 ...
0
votes
1answer
14 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
17 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
31 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
11 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
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
14 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 ...
0
votes
1answer
17 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
25 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
16 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
94 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
14 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
0answers
27 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
1answer
24 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
22 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
26 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 ...
1
vote
1answer
41 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
36 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
19 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
0answers
31 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
0answers
13 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 ...
1
vote
1answer
24 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 ...
0
votes
1answer
38 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 ...
1
vote
1answer
25 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']; ...
1
vote
0answers
24 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
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
31 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
138 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
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
28 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
186 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
82 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
36 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