As of May 31, 2023, we have updated our Code of Conduct.

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
34 votes
2 answers
60k views

How to extract data from a post meta serialized array?

I found an XML to WP decoder script that stores the data as an array in a custom meta field. What is the best way to extract the information? For example how could I display the "Manufactured in" ...
MTT's user avatar
  • 3,518
11 votes
2 answers
12k views

How to store widget fields data as an array?

I am creating a widget, it needs to store about 10 IDs. Right now I'm using following field method to store each of the ID in a separate field. It stores data of each field in a separately in the ...
jay's user avatar
  • 175
3 votes
2 answers
4k views

Limit the post for differents custom post type in the same wp_query

I have three custom post type: books magazine videos Now i want to limit the number of post for custom post type, for example: books => 3 post magazine => 2 post videos => 1 post I used a query ...
rodboc's user avatar
  • 55
19 votes
6 answers
20k views

WP Cron Doesn't Execute When Time Elapses

The goal I want to use wp_schedule_single_event( ) to execute a single event that sends me an e-mail 8 minutes after the user submits a form. The issue The following code is in my functions.php: ...
Mike Madern's user avatar
  • 3,909
4 votes
1 answer
3k views

Metabox repeating fields - radio buttons not saving correctly

I have multiple radio buttons set up inside of a metabox in a custom post type. I have created the metabox like so: add_action('admin_init', 'add_meta_boxes', 1); function add_meta_boxes() { ...
EHerman's user avatar
  • 989
0 votes
1 answer
290 views

assign 2 $args to one wp_query

i need to excute posts from 2 search keywords & put all in one loop to showing by using WP-Query i have trying array_merge but this not worked for me so my last code is: please note: i need to ...
adnan's user avatar
  • 323
3 votes
2 answers
6k views

How do I search an array stored in a custom-field using WP_Query?

I have a custom post type called "on-air" that included a custom-field called "daysonair". The form for this has checkboxes for each day of the week. When you add/update a post, the checked items ...
Dave Navarro's user avatar
2 votes
1 answer
1k views

Use Transient API to cache queries for all posts in all categories?

I use this to display all posts in all categories. $args_cat = array( // order by category name ascending 'orderby' => 'name', 'order' => 'ASC', // get only top level categories ...
lowtechsun's user avatar
1 vote
2 answers
7k views

shortcode to create dynamic dropdown box form shortcode attributes

I am trying to make a shortcode that will create a dynamic dropdown list of downloadable file links, that once selected, html will show a download link below the dropdown. Here is the end result of ...
Jason's user avatar
  • 606
0 votes
1 answer
12k views

Passing a variable into Contact Form 7 [closed]

I have been looking for a solution to this, have seen some sort of add on called dynamic text but I don't think that suits my needs. Basically, I have a multi dimensional array. Basically what I want ...
David's user avatar
  • 141
8 votes
1 answer
6k views

Insert new element to array with add_filter

add_filter('example_filter', function(){ return array( 'tax1' ); } ); add_filter('example_filter', function(){ return array( 'tax2' ); } ); add_filter('example_filter', function(){ return array( 'tax3'...
Ünsal Korkmaz's user avatar
6 votes
4 answers
20k views

Get list of all registered post types slugs

I'd like to get a list (array) of all the post types I registered. Precisely I would like to retrieve their slugs. Could someone help me? thanks!
unfulvio's user avatar
  • 1,784
4 votes
1 answer
572 views

Autogenerate wordpress shortcodes using array?

I was create a shortcode which automatically generate shortcodes with given array key and value. Function names does not generate dynamically. Note: Array KEY = ShortcodeName and Value = Wordpress ...
maheshwaghmare's user avatar
4 votes
4 answers
6k views

Sorting list of sites from multisite network using wp_get_sites

I have a loop that pulls in all sites in my multisite site network and loops through them to get variables located in their ACF options. Here is an excerpt from the code I am using: $stageurl = ...
Morgan's user avatar
  • 489
3 votes
2 answers
5k views

How to set the default value of a option in a theme?

$shortname = "nuod"; array( "name" => "Custom Logo URL", "desc" => "Enter the link to your site's custom logo.", "id" => $shortname."_logo", "type" => "text", "std" => "...
Zhianc's user avatar
  • 176
3 votes
1 answer
1k views

array_pop() expects array, boolean given for $event_type_term ->slug

I have the following function I wrote … add_filter('post_type_link', 'events_permalink_structure', 10, 4); function events_permalink_structure($post_link, $post, $leavename, $sample) { if ( ...
mathiregister's user avatar
3 votes
1 answer
7k views

meta_query with array as value

I am writing some PHP which allows users of my site to submit a form and query posts by their post_meta. Everything works fine except for one thing, I used Advanced Custom Fields to create the ...
tyler's user avatar
  • 113
2 votes
1 answer
1k views

If function exists, and array is met, echo function?

I have a function like the following: <?php echo my_custom_function( array( 'category_url'=>'My Special Category' ) ); ?> It pulls data from the "My Special Category" and displays it. I ...
RodeoRamsey's user avatar
  • 1,697
2 votes
1 answer
7k views

How to fetch serialized data from wordpress options

I have the following serialized data in a wp option a:2:{s:5:"Title";s:11:"your title";s:7:"Message";s:20:"Hola testing testing";} I would like to return it to be used in a form, and show it also in ...
David Garcia's user avatar
2 votes
1 answer
906 views

How do I properly format the user_role array?

I used a role editor recently and needed to delete a role. After deleting it I noticed that it began to appear as blank in the edit user role drop-down. After a bit of investigating and deleting ...
Zach Shallbetter's user avatar
1 vote
2 answers
852 views

Show one post per author and limit query to 8 posts

I want to show 8 recent products from multiple authors on the frontpage. Need to show 1 recent product per author. Currently i'm using basic wp query to show recent 8 products. $args = array ( '...
Erik's user avatar
  • 113
1 vote
4 answers
8k views

Make Selected Mutiselect Items "selected"

I'm developing a theme settings panel for a new wordpress theme that have an option to exclude categories from being shown in the loop. I managed to get the main functionality to work, using a ...
user8220's user avatar
1 vote
1 answer
1k views

Error in WP_update_post

i make php file outside from wordpress folder to edit wordpress post and i get error when i use this code. wp_update_post <?php include '/go1/wp-includes/post.php';?> <?php // Update post ...
Arief saladdin's user avatar
1 vote
1 answer
2k views

How to store post meta in an array?

What is the best way to store post meta in an array (using a custom write box, know how to do that) so that all post meta is in a single custom field?
MTT's user avatar
  • 3,518
1 vote
2 answers
7k views

use get_posts to get custom field data, but in one array

I've run a get_posts query in WordPress and need to pull a pair of custom fields and get all of them into one array. The get_posts query provides an array of posts, but when I use foreach to access ...
chowwy's user avatar
  • 340
1 vote
1 answer
58 views

Placing a div or img in between a post array using WP Query [closed]

I've created a post array inside of the homepage of my clients site. Basically, it's meant to display the six most recent posts of the blog. Now, the client wants the third of those six to be another ...
Adam Bell's user avatar
  • 171
1 vote
1 answer
2k views

Multiple entries in get_option results? or why is _multiwidget set to 1?

I am developing a wordpress widget, and need to store some user configuration values, that is why I am using wordpress update_option and get_option. I am new to widget development. I have some ...
user9's user avatar
  • 154
1 vote
1 answer
2k views

Display WooCommerce product categories in a 4 columns custom menu [closed]

I'm trying to list a set amount of product categories (x) in a dropdown menu, but if the total amount of product categories are greater than x then only list x minus 1 and display “view all categories”...
aye cee's user avatar
  • 159
1 vote
1 answer
234 views

Problem:Save Several Duplicate posts in The Database and then Error nesting level of '100' reached

I have a function to insert a single post in the database. But when I run the function, duplicate posts (40) are added to the database and then an error is displayed. Fatal error: Maximum function ...
Mortzea's user avatar
  • 196
1 vote
1 answer
339 views

Creating a unique, linked list of tags from a specific category?

I am hoping to make a custom tag widget which displays all tags from a specific category. The code I am currently using is working correctly, but it is displaying duplicate tags. I would like to ...
user13286's user avatar
  • 393
0 votes
1 answer
90 views

Updata Metadata WP Rest API

I am trying to update a metadata I created from the front-end with a click event. { "id": 1248, . . . "metadata": { "wishlist_array": [ "" ], . . . ...
stemon's user avatar
  • 145
0 votes
1 answer
340 views

Compare two meta key values against each other inside the get_posts array?

I'm banging my head to the wall all day trying to figure this out. I have two meta keys a1 and a2 with numbers inside. I'm trying to show posts that are a2 > a1. In a nutshell, here's what I'm ...
robert0's user avatar
  • 203
0 votes
2 answers
690 views

post__in - Placing content from a foreach loop inside of an array

I know this code is incorrect, but it's a basis of what I am trying to achieve. I am parsing an xml feed via PHP and running a foreach loop to get a value from a specific key. Here is the snippet I ...
Roc's user avatar
  • 463
0 votes
2 answers
3k views

Comma seperated list of ID's as an array?

I have the following code that prints a comma separated list which I need in the form of an array, how do I get the list of id's into an array called $excluded_categories with contents as per below? $...
Andy's user avatar
  • 215
0 votes
1 answer
317 views

post__in works but also prints the word Array

First line of the code below carries post ids captured via a form. Then rest of the code helps pull the post-thumbnail of the respective post ids $sel_ids = $_SESSION['selected_ids']; if ( ! is_array(...
gurung's user avatar
  • 432
0 votes
1 answer
2k views

Return array of categories to php function

I am looking for a function that will retrieve the names and ids of all categories that will output a checkbox, or give me the data so I can perform a loop. <input type="checkbox" name="category" ...
Evan Yeung's user avatar
  • 3,432
0 votes
1 answer
2k views

WP Meta Query for some meta (array) values

If I get my posts using meta_query by 'my_meta_key' only I get something like this Array( [0] => Array( [nested_key1] => something_I_want1 [nested_key2] => ...
jave.web's user avatar
  • 477
0 votes
2 answers
4k views

how to limit and display tag?

Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any 3 tags randomly. for eg: A sample post <a href="/tag1">Tag1</a> &...
Ezhil's user avatar
  • 389
0 votes
2 answers
1k views

settings api store multiple array

If I am not mistaken, the settings api only storing one single data array in wp_options table. You can only change the field data in the array. What if I want to add multiple array in the same table ...
dev-jim's user avatar
  • 1,898
0 votes
2 answers
8k views

WP_insert_term how to insert multiple values as taxonomny term?

I have this script (found online) to import the values of an input form field as a taxonomy term. I got it working, but now I'd like to import/save the values of multiple form fields. Now all it does ...
RobbertT's user avatar
0 votes
1 answer
2k views

Listing all posts from current category on page

I'm trying to list all posts from a certain category, in a list, on the category page that already lists the posts out in blog form. I'm trying to do it in the header area so that you can get an ...
Phill's user avatar
  • 5