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.

131 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
54 views

Can an array be used as a meta_query value?

I'm trying to query a custom post type (courses) by grade using WP_Query and Advanced Custom Fields (ACF). Grades (checkboxes) are organized by term (groups). Four grades per term, four terms per ...
2
votes
0answers
205 views

How do I dynamically generate args for wp_query?

I am trying to build up my search args depending on variables passed through from a form. What I want to do is add to args if values are present. For example if there are dates I have: $args = ...
2
votes
1answer
286 views

array of objects to do_action, callback gets singular object?

So I was passing an array of objects through an action today, no biggy, and things were working fine. Until I was iterating over one of the arguments to a callback and started getting errors. The only ...
1
vote
0answers
56 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 ...
1
vote
1answer
69 views

foreach loop still echoes array

I'm not sure why the foreach loop is still printing an array for my $education variable. This code is supposed to get the custom post fields. It works with the title, the image and the about variable, ...
1
vote
1answer
294 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 ...
1
vote
1answer
554 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 ...
1
vote
2answers
285 views

Outputting an array of term meta values in a custom WooCommerce tab?

Forgive me – my Wordpress/PHP skills are hilariously rudimentary, so I may not use the correct terminology. I have added a custom tab to the WooCommerce single product page and need it to display a ...
1
vote
0answers
165 views

Using Wishlist Member and I need to access a user's status

I am trying to create a default "Membership Alert" page, so if a user's membership has been cancelled, has expired, requires approval or requires confirmation I want to give them a message on this ...
1
vote
2answers
40 views

Display post content with respect to its title?

I am building a custom loop where I want to display post content only if its title matches a specific string. But I am out of luck on getting this done right. Here is my code so far. $args = array(...
1
vote
0answers
168 views

Storing a many to many post type relationship in post meta and keeping SQL ability for Joins

I have 2 Custom Post types and i am manually keeping a relation between them in a many to many relationship by keeping an array as a custom field. All PARENT post types have ONE filed in wp_postmeta ...
1
vote
0answers
10 views

Selecting and outputting results from DB with an array

I have always had issues with arrays. I can never seem to get them to work correctly. Could someone advise me. I want to make a selection from the database, use that in another selection and then ...
1
vote
0answers
38 views

Order char by post title

This is my code: $args = array( 'post_type' => 'post', 'orderby' => 'post_title', 'order' => 'DESC', 'posts_per_page' => 15, 'tax_query' => array( array( ...
1
vote
1answer
90 views

Checking array against author id in loop

So I have a function in Wordpress with a plugin that returns a list of friends as an array. The function code is here: function friends_get_list($tmp_uid, $friend_status=1) { global $wpdb; $...
1
vote
0answers
620 views

Sort alphabetically by custom field

I'm trying to change the sort order of a custom field in a custom post type. I want it to be be alphabetical by the 'location' name. It's sorting by location, but not keeping them in alphabetical ...
1
vote
1answer
141 views

Custom order for Mysql array

I have a Page of Posts, each post has a Custom Field "expired" which contains a date in the format YYYY-MM-DD which is used to order the posts. This date is used for a script that tells the visitor if ...
1
vote
0answers
114 views

Using shortcode to display array in array

I am using a widget, U more recent posts. Seems to work with custom taxonomies when you input the correct data into it in a widget form, but the suggested shortcode doesn't work (and I am trying to ...
1
vote
1answer
67 views

How to get all users by custom current user meta (array)?

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:...
1
vote
1answer
252 views

Query all posts if multiple meta key don't exist

I'm trying to get all posts that don't have a meta ket that starts with aa_. I can do it this way $args = array( 'posts_per_page' => -1, 'category__in' => 23, 'meta_query' => array( '...
0
votes
0answers
23 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() { ...
0
votes
0answers
14 views

Get all the Tags Assigned to Current User

I am looking to find a way to get all the user_tags. I have 3 Tags applied to the current logged in user I just want to simply get the tags as an array. Something like this: $user_tag = array('29GA ...
0
votes
0answers
32 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 ...
0
votes
1answer
23 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 ...
0
votes
0answers
10 views

show just subcategory array

Looking to see if I can modify the below coding to pull just the category information. Currently at the category level it will pull all the products. Is it possible to just pull the subcategories ...
0
votes
0answers
11 views

Show the subcategory name based on current product

Hi I can display subcategory name in current product page (single product page) but it showed all the subcategory name. I just want to show subcategory name based on the product selected. I have one ...
0
votes
1answer
44 views

update_post_meta adding to array instead of replacing value

update_post_meta() keeps adding to an array instead of replacing value. Any tips? Previously I used add_post_meta() by accident and perhaps that somehow flagged the field as an array? Update So how ...
0
votes
0answers
25 views

AJAX call recieving a 400 bad request when array lenght is to long

I have a select dropdown where users can choose multiple options that get's sent to a custom Rest-API endpoint and returns values based on their selection(s). The dropdown is dynamically populated ...
0
votes
1answer
93 views

Wordpress meta query with meta serialized data array value

Looking for a method to nest AND/OR relation in meta_query based on array serialized values. Reviewed these already: Query multiple meta key values? WP Meta Query for some meta (array) values I ...
0
votes
1answer
25 views

Combine multiple menus using the filter wp_nav_menu_items

Is there a way to combine multiple menus in the functions.php file using wp_nav_menu_items()? I need to hook in a second menu to the main menu. The site has two separate menus in the header. One is a ...
0
votes
0answers
50 views

How to filter specific element of an array in wordpress/php?

I have a php code as shown below in which I have added Line#A for the debugging purpose. <div class="vidlist-main__meta cf"> <?php //if ( has_excerpt() ) {the_excerpt();} $tags =...
0
votes
0answers
33 views

How do I save values from a foreach output on an options page?

I am creating a plugin that outputs a metabox on each page to be able to assign custom meta descriptions plus some other values. All of that works perfectly. However, I also have a "bulk editor" ...
0
votes
0answers
24 views

How can I stop an custom field value from appearing in a dropdown list

I have a dropdown field that displays custom values that I can add from the admin portal. I would like to exclude an option called 'Meal' so it does not show in the dropdown field on the frontend The ...
0
votes
0answers
47 views

Convert number to date format within an array

I have a custom field of deal_date that I need to work into an array. When using directly on a template I can just set the output format directly in the ACF UI. However I obviously cant use get_field ...
0
votes
0answers
19 views

Save post meta save as multi dimensional array

I want to make portfolio page using meta field, where clicking to image opening image slideshows. So I want to loop main clickable image in array and images of slideshow as an array of main image, ...
0
votes
0answers
42 views

WP post meta - for loop inside for loop

I wanna make a portfolio on-click opening images gallery using meta fields. So firstly I make array of portfolio images and loop them. Then I loop gallery images of every portfolio item, but it loops ...
0
votes
0answers
44 views

Staggering featured post using 'sticky'

So I have Custom post type that occasionally will have posts marked as 'featured' Client would like to use the 'sticky' feature of WordPress to pick which posts from the CPT are classed as featured ...
0
votes
0answers
11 views

sql query for selecting btween two amounts

I am trying to achieve the result by selecting dropdown between two amount range. echo '<option value="browse-events?city='.$browse_city.'&type='.$browse_type.'&price=Free">Free</...
0
votes
1answer
381 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
86 views

get_category_parents to array

Ok, So I get a choice from a wp-dropdown. This choice is a category. I use this category to find it's parents. This seem to be outputting a string. This string should be converted into an array. And ...
0
votes
0answers
26 views

How to add each letter, entity, special character from post title to array

I try to add each letter, entity, special character from post title to array but quote symbols not working. I use this function in the loop and single post page. Entities are in the numeric HTML ...
0
votes
0answers
359 views

Notice : Array to string conversion on array_intersect user meta

I am trying to check if two meta data has any common array values. Its returning an error Notice: Array to string conversion in functions.php on line 1026 which is $inbox = count(array_intersect($...
0
votes
1answer
54 views

Repeat array inside array through while loop

I want to repeat this array: array( 'taxonomy' => $tax, 'field' => 'slug', 'terms' => $cat, ) because I am getting the value of taxonomy and categories from custom sub ...
0
votes
0answers
26 views

Remove item from post_meta array via AJAX

I have a form on a page where users can add new text inputs (up to 30 inputs). The entered value of this text input is stored in the post_meta table via AJAX as an array. Here is the php that ...
0
votes
1answer
149 views

Make sticky post with FacetWP

I have WordPress posts in combination with Advanced Custom Fields and FacetWP for filtering. WordPress has an option to make a post sticky, I did this and nothing happenend so I tried to change my ...
0
votes
1answer
57 views

Trouble with calling an imploded variable in an array

I'm having trouble with calling an imploded variable that is then formed to an array and called in a post loop argument. $user_id = um_profile_id(); // Get current user ID $...
0
votes
1answer
113 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
53 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
0answers
567 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
160 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('...
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. ...