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
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:...
0
votes
1answer
138 views

Related Post by Tags Code

The basic function I'm trying to achieve is to get the tags of a current post, find all posts attached to those tags, but then only return posts that have at least 3 tags in common I've been playing ...
0
votes
1answer
209 views

How can get all users by 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:...
0
votes
1answer
491 views

How can get all users by current user meta?

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:...
0
votes
1answer
44 views

How do I add a relation parameter to my filter query?

I am building an AJAX post filter using a single form with three select fields that allow the user to sort by three separate taxonomies (category, region, and country). Everything is working well for ...
0
votes
1answer
334 views

Display posts using post ID's in an array

I currently have an array of post ID's stored as $recenty_viewed that looks like this: Array ( [0] => 3164 [1] => 3165 [2] => 3168 [3] => 3176 ) I'd like to display each post thumbnail and title ...
1
vote
2answers
295 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
votes
1answer
154 views

Populate checkboxes from array

I have a form, that users have to fill out with their informations. The theme I am using, had this to be a select. I changed it to multi select, as we needed people to be able to select multiple ...
0
votes
1answer
107 views

How can i iterate through this shortcode array?

This is how $attr is created: $attr = shortcode_atts( array( 'chart' => null, 'footer_caption' => null, ), $attr, $shortcode_tag ); This is the print_r of $attr in this ...
0
votes
2answers
537 views

Pass a php string to a javascript variable

I need to pass a php string that is stored in $attr['footer_caption'] inside a shortcode function to a js file where the highcharts are initialized. $fields = array( array( '...
1
vote
2answers
1k views

How am I able to get the value out of cookie array when I push a button?

I have made a favorite plugin. With a shortcode I'm able to display the button to 'a wish/favorite list' anywhere I want the button. This button is for adding the post_IDs of pages/posts/blogs/...
0
votes
2answers
149 views

Querying another post category to match current post and display in loop

I'm trying to query a custom post type's category to display in another custom post type, but only if they have matching categories. I'm new to coding a fairly complex WordPress site from scratch (it'...
0
votes
1answer
167 views

Post meta as array looks like string instead of array

I want to insert an array into a post meta, but something strange is happening. What am I missing here? How I insert meta to a post: // 1st Quarter for ($month = 1; $month <= 3; $month++) { $...
0
votes
1answer
1k views

“Undefined variable: array” Error In Displaying Post Tag

I'm trying to display the post tags through a widget, I've following codes and getting error "Undefined variable: array": if ( $instance['stats_tag']['category'] ) { $posttags = ...
0
votes
1answer
349 views

Working of foreach loop with array

I'm trying to understand a piece of code I found online to create customized user login page. Here I'm unable to understand how foreach loop works (specially this line: $page_definitions as $slug => $...
0
votes
1answer
38 views

Get the id of all images in a post

Im trying to get the id of images from a post. i've tried with wp_get_attachment_url( $id ) and some other options but always get an empty array when i do var_dump or print_r. Whats the correct way to ...
-4
votes
2answers
822 views

Force array to be a string [closed]

Im using a charts plugin an i need to force some array elements to be strings. $values_x = array(); for ($i = 0; $i < count( $series[0]['data'] ); $i++ ) { $values_x[] =...
2
votes
1answer
156 views

Using a javascript file to access a get posts array

I would like to use arrows to dynamically change which posts appear in a div by cycling through an array of say 5 posts. How would i approach this issue? I have made the array that the get posts ...
1
vote
1answer
155 views

How to properly loop through these external URLs to get them into the sitemap using this hook

I have filtered Urls that I would like to add to push into a sitemap. I am using one of the sitemap plugins, which has hooks to further modify it. my code: // add to theme's functions.php ...
0
votes
1answer
100 views

construct complex queries with WP User Query

Is it possible to create complex query with WP User Query ? With WP Meta Query, we can make complex queries with Nested arrays like : $meta_query_args = array( 'relation' => 'OR', // Optional,...
0
votes
0answers
380 views

meta_query for user ID in array

I'm an attempting to query a meta value (array) of user IDs: $meta_query = [ [ 'key' => '_votes_round_2', 'value' => $current_user->ID, ...
0
votes
1answer
166 views

Exclude posts based on meta value

I have run into a problem with arrays. I need to overwrite search query and exclude posts. To do that, all I need is to exclude posts that have meta value called "hide_this_page" equal to "Yes". So ...
1
vote
2answers
50 views

Make an array filterable per hook

How can I use do_action and add_action to return an array in do_action? My sample code: function name_fun_one(){ $namearray[] = array('k1'=> 'text1', 'k2' => 'text1'); $namearray[] = ...
1
vote
0answers
32 views

How can i send multiple value using get_option(); [duplicate]

If suppose I have :- function dr_add_adminp() { // Generating dr_theme_options Admin page add_menu_page( 'USR THEME OPTIONS', 'User Options', 'manage_options', 'theme_options', 'theme_page', ...
0
votes
2answers
35 views

Do not replicate items if they exists in a foreach loop

My head is clearly not working here. The logic is simple but I can't seem to get it right. I have a tv schedule post type and I want to display: 2016-12-01 2017-04-01 2017-05-17 Instead of: 2016-...
1
vote
1answer
982 views

get_tags() return an empty array after added tags with wp_insert_term()

I added some Tags programmatically with wp_insert_term(), and later I call get_tags() to use them, but it returns an empty array, although they are inserted in the database. Here is my code: install....
0
votes
1answer
624 views

Output category list inside array

I need to output information about each of my post categories in this array, but I'm having trouble figuring out how. I need to output each category as an array (See examples) under the values option ...
0
votes
1answer
480 views

wp_set_object_terms not accepting variable array

I am trying to use the following command: wp_set_object_terms( $myID, $myissuearray, 'my_issues', true ); But for some reason, it won't accept my variable array. That array, $myissuearray, using ...
0
votes
1answer
359 views

Convert Custom Post Data to Javascript Array for Autocomplete

I am creating a metabox that utilizes jQuery Autocomplete to display custom post data. How do I get this data: $args = array( 'post_type' => 'promo' ); $loop = new WP_Query( $args ); while ( $...
1
vote
0answers
175 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 ...
0
votes
1answer
164 views

Display a single row from nested array of custom field data

I built an Exercise custom post type with a custom field group using Advanced Custom Fields. The structure uses repeater fields for Week, Day, and Exercise, which creates a series of nested arrays. It ...
0
votes
1answer
870 views

how to make an array of post id's in is_single

For example, the code below only shows the page challenge for post id 2578. However i got 8 other posts that should have the same layout. All others should have the layout from challenge-2 etc. I was ...
2
votes
2answers
493 views

Need to get specific data from array

I'm building a custom carousel for a client. I've got a function which gets blocks of three images from all of the images attached to a post: global $rental; $images = get_children( array( '...
0
votes
2answers
236 views

date_query problem

I'd like to get the closest post to today's post; yes, I checked and search this topic and found the code working for me: date_default_timezone_set("Europe/Warsaw"); setlocale(LC_ALL, en_GB); $year = ...
0
votes
2answers
22 views

How to assign results to variables?

Here is what I have so far: function get_highest_bid_info(){ global $wpdb; $postid = get_the_id(); $table = $wpdb->prefix . "jwp_bids"; $wpdb->get_results( "SELECT email,...
2
votes
3answers
1k views

Saving an array in a single custom field

I have the following array that I want to store in a single custom field. array("Accounting"=>"Peter", "Finance"=>"Ben", "Marketing"=>"Joe"); I want to store it by typing it in a custom ...
0
votes
1answer
21 views

Filtering a function' output for a new continued function

Alright let me explain. I am using a function to get all Wordpress Tags and display them. That is fine.: What I'm trying to do is display these tags first in one place where space is limited and then ...
0
votes
2answers
458 views

How can I split my query result in 2 arrays?

I have made a query which gives me 8 results. I need to show these in 2 columns of 4 items. This is my query : $args = array( 'post_type' => 'event', '...
0
votes
1answer
95 views

WordPress text field in array problem

This my code. $idsposts = solstice_get_opt('slider_4'); // example: 443,755,155,282 $myposts = array($idsposts); // must be array(443,755,155,282) but i saw array(443) $...
0
votes
1answer
70 views

Get title from IDs in a string

Im trying to get titles from IDs in string, but I'm getting stucked when I want to use get_the_title() function and receving error implode(): Invalid arguments passed $act_name = explode(',', $...
0
votes
2answers
466 views

How to save array option as text and not integer?

Im in the midst of customizing WooCommerce checkout, adding a dropdown field which get user's meta keys and show as select option in the checkout page. I also managed to save the selected option after ...
0
votes
1answer
139 views

How to replace hard-coded list of custom taxonomy terms based on custom field query [closed]

I am currently hard-coding custom taxonomy terms "13329,5555" into a block of code. Instead of hard-coding the custom taxonomy product_cat term_id as "13329,5555" how would I dynamically replace 13329,...
0
votes
1answer
40 views

How do I pull post from standard post format?

I use this code to take a post from the post format. $query = array( 'showposts' => 5, 'post_type' => 'post', 'tax_query' => array( '...
2
votes
2answers
66 views

Create an array from an array

I've got an array of images attached to a post, and can output them sequentually just fine: 1 2 3 4 5 6 7 How can I get three images at a time from the array, then step one image forward to create ...
1
vote
0answers
3k views

Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]

I've been trying to create a simple shortcode function so I could display in the frontend of my website a list of available Shipping Zones along with their most reliable information such as the zone ...
0
votes
0answers
142 views

Cant get unique_array() work on get_the_category() foreach loop

i'm trying to list user's posted categories (main ones only) on the author.php I have prepared this loop but it has duplicated content <?php if ( have_posts() ) : while ( have_posts() ) : ...
0
votes
1answer
663 views

Multidimensional Array

I have an array in my wordpress template where i want to then target a specific status of the logged in user. Below is what i currently have with the $args containing a status with all the status ...
0
votes
1answer
21 views

Get a list of tags present in a paged front page

I need a list of post tags, only the tags present in the posts shown in a paged front page. So, my first step is to build an array with this tags. This is what I did: 1. Declare an array in the ...
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(...
0
votes
1answer
58 views

Output checkbox per user and save in plugin options

I am looking for a way to save my list of checkboxes as an array within the settings_fields of the plugin. I currently have: <?php $WPusers = get_users( 'orderby=nicename&role=administrator'...