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.

143 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
57 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
225 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
330 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
22 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
9 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 ...
1
vote
0answers
34 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
25 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
161 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
99 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
331 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
684 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
373 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
210 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
41 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
173 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
39 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
102 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
676 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
142 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
118 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
70 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
284 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
8 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
2answers
22 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
0answers
21 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() ...
0
votes
2answers
88 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 ...
0
votes
0answers
23 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: $...
0
votes
0answers
61 views

How to get Wordpress post filter (misha_filter_function) to filter CPT categories associated with a tag

I'm using the misha_filter_function from: https://rudrastyh.com/wordpress/ajax-post-filters.html to filter posts. The initial array is displaying the correct posts by the location_and_season (made ...
0
votes
0answers
12 views

Accessing array elements WOOCOMMERCE API

I would really appreciate who can guide me with the following: I have the following ARRAY, it is a record of a product in woocommerce-wordpress that RETURNS three DIFFERENT variations: 1837, 1838 and ...
0
votes
0answers
25 views

WP_User_Query Orderby Not Working

If I use the following code, I can retrieve users in the correct order: $user_query = new WP_User_Query( array( 'role__in' => wp_parse_list( $atts['userrole'] ), 'meta_query' => ...
0
votes
1answer
35 views

wp_insert_post($post), add an array of values with update_post_meta

i try to store an array in multiple custom fields via post creation (wp_insert_post). The array is $event_test and the key is event_test on the meta_input. On form submit, the custom field is shown, ...
0
votes
0answers
21 views

Loop through an array and find the ID in another array

So I'm having some trouble with my looping and I would like to resolve it if possible. Below, I will go into detail on what I currently have: $test = strtoupper(str_replace(' ', '', trim($record->...
0
votes
1answer
27 views

How to create an array if 'empty'?

Sorry if this is super "newbie", but I'm stumped. I'm trying to create a function in WP All Import that states if the cell is empty it populates with "Not Specified". Please see below: function ...
0
votes
0answers
17 views

Display Specific Parent and Child Category Lists with Format

I have a code that I want to display in lists. <nav> <ul class="simplefilter filter-port"> <li class="btn active button btn-hover" data-filter="all">All</li> ...
0
votes
0answers
84 views

Get user count based on multiple meta key values?

I am trying to count all of the users meeting multiple criteria. I have tried so many different things and cannot get it to work. Any help is much appreciated. Thank you. add_shortcode('...
0
votes
1answer
18 views

Ordering of posts, 2020 Year showing as next event when should be last

We have some event posted into wordpress which are ordered by date. All works well except when we enter an event for 2020 it comes at the top of the list rather than the bottom. The date is save in ...
0
votes
1answer
28 views

Loop through array of pages

I am trying to recursively get all children of a page (infinite depth) and I am using function below, from this solution: function get_all_subpages($page, $args = '', $output = OBJECT) { if (! ...
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
17 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
105 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
85 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
17 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
149 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
33 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
293 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
46 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
74 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 =...