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

Multiple meta key and value search in the query

I am have this following API code for $_REQUEST $metakey = explode(',',$wpdb->escape($_REQUEST['key']) ); $metavalue = explode(',',$wpdb->escape($_REQUEST['value']) ); $meta = ...
0
votes
1answer
2k views

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

Checking the Query Monitor its 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 ...
1
vote
1answer
947 views

Get posts id in array by meta value and key

How to get all posts ids that has a meta key and value. $meta_key = 'hide_rss'; $meta_value = 'yes'; $post_ids = array(1, 2, 3);
1
vote
2answers
3k views

Check if term object is in array

I want to check if a term object is in an get_terms array, but i really can't figure out how to do it. $subcat_terms = get_terms([ 'taxonomy' => 'product_cat' ]); $subcat_terms generates an ...
0
votes
1answer
115 views

Orderby post__in Not Working Correctly?

I've created an array based on the numerical values of an object. After which I removed everything in the object in the array, except for the ID. So it ends up looking like this: [115, 123, 66, 64] ...
0
votes
1answer
55 views

How add a custom posttype name using ACF field to a query post array

I'm loading custom post type to different pages by changing cat id and sometimes post type name query_posts(array( 'post_type' => 'posttype_name','posts_per_page'=>-1, 'tax_query' => array( ...
0
votes
2answers
197 views

How can I access string value in an array?

currently I am developing a site using the Dokan multivendor plugin. I added a custom field in the registration form and The below code is being used to add the custom field in the registration form ...
0
votes
1answer
626 views

get_terms() returns Trying to get property of non-object error for custom taxonomy

Created custom post type and now I'm trying to create a custom taxonomy. Once I create it and try to access it with get_terms() I get an error of non-object. Var_dump is giving me an empty array ...
1
vote
1answer
36 views

How to add day number and initial to my post graph?

I have been building this recent-post-count dashboard widget graph - or, more accurately, modifying and refining a comment-specific version, for posts. I'm really pleased. Some of it may be ...
2
votes
1answer
47 views

Get (echo) all role names assigned to user

Im trying to do something which I feel should be quite easy but I can't seem to quite grasp. I have the below code which echo's users roles. Great. Fantastic. BUT I have a problem when a user is ...
1
vote
1answer
265 views

Modify foreach loop for social sharing links?

How would I amend the following foreach loop so each link displays the keys from each nested query, and not just the values? I am creating my own social sharing links, included using get-template-part,...
1
vote
1answer
918 views

Too slow when using both 'tax_query' and 'meta_query' both in WP_Query

I have added the full array in end of the post. I have passed 'post_type', 'posts_per_page', 'tax_query' and 'meta_query' for WP_Query. This page take around 10 - 15 seconds to load... It is too much ...
0
votes
2answers
561 views

How to insert new element to existing array in usermeta?

How to insert new element to existing array in usermeta? This code doesn't work because it makes nested array. $data = array( get_user_meta(2, 'fruits', false), 'apple', 'pear', 'peach' ); ...
0
votes
1answer
237 views

Save meta value as an array of arrays

How to save metavalue in the following format: array( array( 'title' => 'something', 'price' => 'something', ), array( 'title' => 'something', 'price' => '...
0
votes
1answer
2k views

Filter by field with array value in ACF on WP REST API

I'm suffering for weeks trying make a GET call in the WP REST API where I have a field in the ACF plug-in with multiple select, and the stored value is an array(). Example of the response after the ...
0
votes
0answers
585 views

Featured image on archive page based on post type

Is it possible to use a custom featured image on the archive page? I created a secondary image space using the code below and would like the featured image to pull from that source vs the default '...
0
votes
0answers
169 views

Strange Behavior with update_option

If I run the following code in the debug console on my WP install, I get the expected behavior: <?php $option = get_option('fun_options'); var_dump($option); $new = array(); update_option('...
2
votes
2answers
2k views

Get Term names from WP Term Object

I created an array with this expressions: $taxonomies = get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => false, )); And I got this as return: Array ( [...
1
vote
2answers
676 views

Echo specific term in an array

I have a custom hierarchical taxonomy ('location') that looks like: Tokyo --Minato ----Roppongi I have a post where only "Roppongi" is selected and I want to display as text only the top level ...
0
votes
1answer
55 views

Sorting Posts by Taxonomy thats not within the query's $args

I’m displaying posts currently using the WP_Query, which doesn’t include the state taxonomy within the $args because I do not want the state to be within the query. But I do want to display the state. ...
2
votes
2answers
119 views

Meta box io oembed returns list not array

i have created a meta box oembed with clone: function media( $meta_boxes ) { $prefix = ''; $meta_boxes[] = array( 'id' => 'media_1', 'title' => esc_html__( 'Media', '...
0
votes
1answer
144 views

Wordpress query reverse order

$args = array('post_type' => 'etlap', 'posts_per_page' => 5, 'post__in' => $ids, 'post_status' => 'any', 'orderby' => 'post__in'); I want to make the orderby status reversed. How is it ...
0
votes
1answer
81 views

Loop through an array inside a class using foreach [closed]

I'm creating a class in my WordPress template and I have a multidimensional array as protected member. The array at second level contains some email addresses as string and I want to get those emails ...
0
votes
1answer
157 views

extract serialized array to use for wp-query

I use wp-query and I need to display posts by author, using author id. This is the serialized array: a:19:{i:0;s:2:"89";i:3;s:3:"105";i:4;s:2:"74";i:5;s:3:"111";i:6;s:3:"167";i:7;s:2:"83";i:8;s:2:"...
0
votes
1answer
66 views

Problem with displaying HTML content after in_array [closed]

I'm trying to create layout based on this question and answer. First of all, it took me ages to understand why if there's only one post in the category, it's not showing up - so I found out that ...
-1
votes
2answers
293 views

How do i output images from URL's added to the same custom field key

This is my array of image URL's added to the same custom field named images. $images = get_post_custom_values( 'images' ); I need to print all these images in a template file.
1
vote
1answer
150 views

Combine get_page_by_title to exclude pages from wp_list_pages

I am using get_page_by_title to exclude a few pages from wp_list_pages, my code looks like: <?php $page1 = get_page_by_title('title1'); $page2 = get_page_by_title('title2'); ...
0
votes
1answer
1k views

array_filter warning - wp-includes/post.php line 3148

I inserted the following code, see below, to have a post submitted from the front-end. When you submit it, this warning appears: Warning: array_filter() expects parameter 1 to be an array, string ...
0
votes
1answer
244 views

Can't access PHP array inside script localization from javascript

I have a loop to retrieve all users with the specific meta_key user values from wp_user_meta database and then put it in wp_localize_script array so I could access the data with Javascript and do my ...
0
votes
1answer
371 views

wp_update_post to set post IDs to drafts not working

Specifically WooCommerce Product Pages. I'm using WP_Query to generate the array. $params = array( 'posts_per_page' => -1, 'post_type' => 'product', 'orderby' => 'menu-order', ...
0
votes
0answers
155 views

Fatal error when using array_diff() function inside of wp_update_nav_menu hook?

I'm attempting to use the PHP native array_diff() function inside of a custom function that is attached to the wp_update_nav_menu hook: function my_nav_menus( $nav_menu_id ) { // .........stuff $...
-1
votes
2answers
45 views

How to combine array info [closed]

Array ( [0] => Array ( [week-day] => tuesday [day-date] => 1511841600 [events_ids] => Array ( [0] => 83417 ) ) [1] => Array ( [week-day] => wednesday [day-date] => ...
0
votes
1answer
82 views

How can i use if statement like this? [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="...
1
vote
1answer
30 views

Remove admin menu links for multiple users by email

I've got 3 admin users and would like to modify admin menu for 2 of them by their email address, not by role (since the capabilities are all the same). This works with a single email address: ...
0
votes
1answer
5k views

PHP array to jQuery array “ Uncaught SyntaxError: Unexpected token < ”

I am trying to pass my php array to jQuery array but I am having this error on chrome console Uncaught SyntaxError: Unexpected token < functions.php /*Call Jquery for dropdowns*/ function ...
0
votes
1answer
145 views

Create multidimensional array of taxonomies

Create multidimensional array of taxonomies Hello all, I need to create a multidimensional array to populate my select via javascript. At the beginning are two selects of taxonomies, 'store' and '...
-1
votes
2answers
137 views

Fatal error in my WP

Everytime I try to login my WP, this fatal error appears and I have no idea of what happened and how to solve. Can anybody help me out? I've got "zero" knowledge in programming and coding. This is ...
0
votes
1answer
70 views

If custom taxonomy exist on post?

I have custom taxonomy called ‘filter’ and if the post has the ‘filter’ ‘reel’ I want to use this loop else use another. $work_tax = wp_get_post_terms( $post->ID, 'filter' ); if (array_key_exists(...
0
votes
1answer
124 views

get users search not working with array

Here's my code: function prefix_get_users(){ $args=array( 'blog_id' => $GLOBALS['blog_id'], 'search' => 'mark' ); $all_users=get_users($args); $arr=array(); foreach (...
0
votes
1answer
388 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 ...
-1
votes
1answer
100 views

What is this mark for “? function()” [closed]

I was working through someone else's code trying to understand their plugin so I could combine it with another plugin to do something different. I have no clue why this question mark is here in the ...
0
votes
1answer
203 views

get_users when from meta key that has serialized values

I am trying to do a get_users() when the meta key has two values. For instance, in the db it looks like this : a:2:{i:0;s:10:"31.08.2017";i:1;s:9:"username";} When I do my query : $claimed_users = ...
0
votes
1answer
59 views

How i can extract data

Hello i have form with nested repeater field, all data in nested repeater group saving in database like this: a:6:{i:0;a:4:{s:5:"title";s:21:"Initial ";s:11:"description";s:78:"Please show identify.";}...
1
vote
1answer
305 views

How can I make my options in an array and store theme in WP options one DB row?

I am making a theme with theme options but for customization, I have completed my theme options more than half. Suddenly I have triggered one problem and that is I have checked my wp_options DB I have ...
0
votes
1answer
48 views

make an array in wordpress cusmization api?

i'm trying to make an array in wordpress customize.php i do used wp_localize_script in function.php as follow function mytheme_scripts() { wp_register_script('scripts', ...
1
vote
1answer
24 views

How to check the array of featured images IDs

I'm trying to show some specific text on top of the featured images depending on their IDs. Some of the featured images will have the same text. $post_thumbnail_id = get_post_thumbnail_id(); if($...
0
votes
1answer
20 views

Trying to select 1 item from an array

I am trying to get 1 item from an associative array that I am outputting form an ACF field. I am doing the following: print_r(get_field('consultant_name')); This is on the ACF field where I can ...
0
votes
1answer
55 views

Code executes outside of Loop while same code gives 'Uninitialized string offset' notice inside a while loop

It's strange that when I run the code below in a function, it executes it, but when I run it inside a while loop it gives me this notice: Notice: Uninitialized string offset: 4 function thing($...
1
vote
3answers
305 views

Parsing php string in jquery [closed]

I am sending php array using serialise but the response is different. Here is my attempt $array = serialize($out); var_dump(serialize($array)); //string(58) "s:50:"a:2:{s:9:"sidebar-1";i:5;s:12:"...
1
vote
1answer
2k views

Looping through WP_Post Object

I have a custom WordPress post array that looks like this: Array ( [1] => Array ( [sno] => 1 [post] => WP_Post Object ( [ID] => 1452 [post_author] => 12 ...