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

Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query

I'm building a function into a shortcode to retrieve information relative to a custom post. For the most part, I can retrieve everything I need with the following, despite (probably) not being the ...
2
votes
1answer
28 views

Show post only if match all categories

I have posts that have multiple different categories including a common category called "Videos", now I'm trying to show only posts that match with the all categories of the main post ...
0
votes
0answers
9 views

Help with get_post_gallery_images()

everyone. I'm trying to use get_post_gallery_images() to retrieve URLs to the images in a gallery in the post I'm using the function. I read that this function will return a string of URLs for the ...
0
votes
0answers
14 views

“WordPress database error: You have an error in your SQL syntax” when using array_filter();

I try to update WP database custom table with form data and everything is OK. BUT one error doesn't give me peace of mind. WordPress database error: [You have an error in your SQL syntax; check the ...
0
votes
1answer
11 views

PHP | left join avg query give me Array()

I'm trying to implement a query within my code that gives me the ability to calculate the average value between the ratings received and the number of ratings per post, and sort posts from the one ...
0
votes
1answer
34 views

WP Query by 4 different taxonomies

I need to make a shortcode that uses the values of four different taxonomies. I am trying to modify code that I have used to query attachments (in media) based off of multiple taxonomy terms, but ...
0
votes
0answers
18 views

How to use multiple (or array) values in $content of shortcode?

I have a shortcode that fetches some values, first_name, last_name and email from a remote database. I'm trying to write a shortcode that will allow me to print 2 or more of those values within output ...
0
votes
1answer
16 views

Trouble with serialized metadata

I've read about 20 different posts on this topic and I still can't apply the solutions to the problem I'm having. I'm very sorry for not being able to figure it out based on those answers, but I ...
0
votes
0answers
15 views

How to get posts by meta value as multi-dimensional array?

I know how to get posts by a specific post meta when the meta value is a string. $meta_query = [ [ 'key' => $meta_key, 'value' => $meta_value, 'compare' => '=' ...
0
votes
0answers
30 views

How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?

More detailed: I'd like to use the the number of items which were bought by somebody and multiplicate it with a number, to show how much water somebody saved. function random_message(){ $...
0
votes
1answer
28 views

Foreach loop inside an array_merge

I need to get a list of users display names in a dropdown menu. I have the query right, but I'm not sure how exactly to get my user foreach inside of an array. Here is the code I need to inject the ...
0
votes
0answers
41 views

How to exclude child categories from multiple parents in WP_Query?

I have some code <?php $exclude_category = [10]; $company_category_parents = get_categories( array('child_of' => 5) ); foreach ($company_category_parents as $...
0
votes
1answer
25 views

Access to numerically indexed array in wpdb Class and undefined offset

the following database call $einzel = $wpdb->get_row("SELECT t.id, DATE_FORMAT(t.datum, '%d.%m.%Y'), DATE_FORMAT(t.datum2, '%d.%m.%Y'), t.ueberschrift, t.uhrzeit, t.termintext, t....
0
votes
1answer
59 views

issue with if/elseif in_array inside foreach loop display only one post

I try to attribute a specific background-color to each post if one of categories of post corresponding to one category. My function works but is restricted to display only one post in result. If I ...
0
votes
0answers
8 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
89 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
22 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
1answer
27 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
49 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
23 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
38 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
13 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
50 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
28 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
48 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
6 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
109 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
16 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
18 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
537 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
17 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
40 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
19 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
23 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
96 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
27 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
17 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
258 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
15 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
31 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
26 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
32 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
27 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
45 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
41 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
48 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
14 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
25 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
103 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'=&...

1
2 3 4 5
14