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
2 votes
1 answer
3k views

How to update serialized post meta?

I have serialized post meta. And i want to update single meta key. It looks like this: In array: $kisiArray = array( 'option1' => 'foo', 'option2' => 'bar', 'option3' => 'apple', ...
wpdev's user avatar
  • 539
0 votes
1 answer
151 views

How to display line breaked meta values in table?

I have meta_key 'oyuncular' and it has meta values with line breaks. I want to get them and display in table with two column. Name and Role Name $names = get_post_meta( get_the_ID(), 'oyuncular', ...
wpdev's user avatar
  • 539
0 votes
1 answer
389 views

How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\.......\wp-includes\class-wp-hook.php on line 286

I am creating Wordpress Dashboard Menu: add_action('admin_menu', 'personalised_menu'); function personalised_menu() { add_menu_page( 'Page Title' , 'Blog' , '...
Yateesh Kumar's user avatar
4 votes
1 answer
292 views

How to build widget with arrays inside arrays?

I've started building a widget that needs to have an array inside an array. I'm trying to get the widget to have the ability to create multiple elements that will display on the site, but also has ...
S_E's user avatar
  • 53
1 vote
1 answer
216 views

How to list custom fields as headers and list all pages sharing that custom field under it?

I'm trying to use a custom field of "State" to list all the city pages for available locations. I'm able to get the right results, in the (alphabetical by state) right order with this code: <?php ...
hellosisyphus's user avatar
1 vote
1 answer
715 views

Add multiple tags to multiple posts

I have an array of posts IDs like this: $id_post_array_full=array(239,243,246,248,250,252,255,257) I would like to add tags for each posts with this function of wordpress wp_set_post_tags(). My real ...
Elle's user avatar
  • 113
0 votes
2 answers
8k views

how to get post order by post id wp_query?

I have 4 posts and I displaying 2 posts per page. $ids = array('16085','16088','16083','16091'); $options = array( 'post_type' => $post_type, 'posts_per_page' => $posts_per_page,...
Bhautik's user avatar
  • 207
1 vote
1 answer
462 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, ...
Remco's user avatar
  • 125
0 votes
1 answer
251 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 ...
sultan's user avatar
  • 19
1 vote
1 answer
2k views

update_post_meta() with a modified array?

When in wp-admin I want to manipulate one value of an array and then update the post_meta with this array. My array looks like this: 1285 array(1) { [0]=> array(2) { ["description"]=> ...
RobbTe's user avatar
  • 242
-1 votes
1 answer
23 views

PHP Use Declared array Variable inside already Declared Array

i have created one class in which i declared public associative array. class test{ public $basicCols= array( array('title'=>'KEY', 'field'=>'slug','options'=>$optList), array('...
Allex's user avatar
  • 13
0 votes
1 answer
361 views

Matching slug terms from one array to those in array of WP_Term objects to output term names

I'm using WordPress's get_terms to return an array of WP_Term objects containing the term_id, name, slug, etc. for the child terms of a given taxonomy. I've saved this array to $tax_terms. I have a ...
nickpish's user avatar
  • 217
1 vote
2 answers
2k views

How can I add multiple 'tax_query' arrays via a loop?

I'm trying to build functionality (using the Advanced Custom Fields plugin) to list information in a page template for all custom post types ('Product') that have specified taxonomies. This is my ...
LCW's user avatar
  • 23
1 vote
1 answer
124 views

How can I pick a single post from the latest 3?

I'm looking to display a single featured post from my latest 3 posts at random. I've managed to get it up and running picking any post at random just fine, but I want to filter it down to only the ...
adamdanw's user avatar
0 votes
0 answers
54 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 ...
Sam Skirrow's user avatar
0 votes
1 answer
569 views

change order of images attached to post

Im not quite sure how to explain my issue so let me know if Im unclear about anything. I have on my front-end post form a multiple file upload input that uploads files to my specified folder and ...
730wavy's user avatar
  • 193
0 votes
1 answer
35 views

Is there a way to add a new value into a stored custom field value?

I am trying to save some numbers into the posts as a custom field in different times. I want to store an array that includes selected numbers for each posts. But I can't update the current values (...
D. Merchant's user avatar
0 votes
1 answer
2k views

Website Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Wppr_Public' does not have a method 'amp_support'

Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Wppr_Public' does not have a method 'amp_support' in /home1/thrfolde/public_html/3foldtraining/wp-includes/class-...
Tina Shahani's user avatar
0 votes
1 answer
687 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 ...
user2812779's user avatar
0 votes
1 answer
288 views

WordPress i18n in Array throws Error

i am wirting my very first plugin. For publishing it to the repository i want to make it translatable. On my options page i some arrays, which store the default settings. Somehow i get an error when ...
JUVO_Webdes's user avatar
0 votes
1 answer
39 views

Add first letter of titles to array, then compare arrays

I have a custom post called foundation_firms, from which I'd like to create an array of letters, each letter representing that there exists a post starting with that letter. I've been trying to use ...
dSumner.1289's user avatar
0 votes
1 answer
124 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 $...
Jake Punton's user avatar
1 vote
1 answer
741 views

var is undefined in a Gutenberg block

I'm fiddling with Gutenberg right now and I'm stuck trying to build a dynamic block. This is the code I'm using (some code is omitted for clarity): registerBlockType( 'my/block', { title: __( 'My ...
leemon's user avatar
  • 1,898
0 votes
1 answer
151 views

I'm unable to call img path using single quotes in an array?

I would like to call an image next to input field in wp comment form. But I'm unable to do that. I call image when '' <= single quotes doesn't exist. But I don't know how to call an image in single ...
user9637601's user avatar
0 votes
1 answer
179 views

Print specific values stored in a post meta array

I'm triing to print some values stored in a post meta. My post meta_values looks like this : a:3:{s:6:"amount";s:117:"€2.00";s:6:"entity";s:5:"11854";s:9:"reference";s:9:"800146779";} I'm ...
Luis Marques's user avatar
0 votes
1 answer
44 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 = ...
l6ls's user avatar
  • 331
0 votes
1 answer
7k views

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

Checking the Query Monitor, it's 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 ...
Demonix's user avatar
  • 41
2 votes
1 answer
4k 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);
wpdev's user avatar
  • 539
1 vote
2 answers
8k 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 ...
Gabriel Souza's user avatar
0 votes
1 answer
649 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] ...
Logan C's user avatar
  • 29
2 votes
1 answer
108 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( ...
Roshan Deshapriya's user avatar
0 votes
2 answers
534 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 ...
M.S Shohan's user avatar
0 votes
1 answer
1k 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 ...
Limpuls's user avatar
  • 307
2 votes
1 answer
72 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 ...
Robert Andrews's user avatar
2 votes
1 answer
123 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 ...
LB79's user avatar
  • 155
1 vote
1 answer
872 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,...
user avatar
4 votes
2 answers
4k 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 ...
I am the Most Stupid Person's user avatar
1 vote
2 answers
3k 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' ); ...
J. Joe's user avatar
  • 13
0 votes
1 answer
513 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' => '...
Raju's user avatar
  • 11
0 votes
1 answer
3k 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 ...
Danilo P. da Silva's user avatar
0 votes
0 answers
1k 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 '...
Ken's user avatar
  • 101
0 votes
0 answers
278 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('...
Robin Andrews's user avatar
2 votes
2 answers
8k 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 ( [...
MysticUnicorn's user avatar
1 vote
2 answers
2k 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 ...
Gecko Boy's user avatar
0 votes
1 answer
68 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. ...
Aisha Henderson's user avatar
2 votes
2 answers
198 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', '...
Phaidonas Gialis's user avatar
0 votes
1 answer
408 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 ...
DeluxeD's user avatar
  • 19
0 votes
1 answer
334 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 ...
Azzaz's user avatar
  • 33
0 votes
1 answer
666 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:"...
Michel's user avatar
  • 37
0 votes
1 answer
94 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 ...
Anda's user avatar
  • 57

1
3 4
5
6 7
16