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.
40
questions
26
votes
1answer
50k 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" ...
11
votes
2answers
11k 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 ...
3
votes
2answers
3k 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 ...
19
votes
6answers
16k 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:
...
4
votes
1answer
2k 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() {
...
0
votes
1answer
214 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 ...
1
vote
2answers
6k 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 ...
0
votes
1answer
11k 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 ...
-1
votes
1answer
255 views
How do I just display the part of the array that I want to? [closed]
I would like to take a stored array, from the meta_value $custom_repeatable and just display the line 'hamsters repeat one', but the following code doesn't display it how I'd like.
Here is the code:
...
3
votes
2answers
5k 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 ...
2
votes
1answer
855 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
...
8
votes
1answer
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'...
4
votes
4answers
15k 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!
4
votes
1answer
473 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 ...
2
votes
1answer
6k 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 ...
4
votes
4answers
5k 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 = ...
3
votes
2answers
4k 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" => "...
2
votes
1answer
790 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 ...
2
votes
1answer
6k 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 ...
1
vote
3answers
7k 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 ...
1
vote
1answer
175 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 ...
0
votes
1answer
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" ...
0
votes
2answers
3k 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>
&...
0
votes
2answers
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?
$...
3
votes
1answer
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 ( ...
2
votes
1answer
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 ...
1
vote
1answer
759 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 ...
1
vote
1answer
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?
1
vote
1answer
44 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 ...
1
vote
2answers
5k 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 ...
1
vote
1answer
223 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 ...
1
vote
1answer
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 ...
0
votes
1answer
40 views
Save data from a checkbox to a wpdb array
I have several fruit checkboxes but when saving to the wpdb database it only saves the last one that it checks, variable $check receives vardump string (6) "banana" string (5) "apple&...
0
votes
1answer
895 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ā...
0
votes
1answer
59 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": [
""
],
.
.
.
...
0
votes
2answers
470 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 ...
0
votes
1answer
182 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(...
0
votes
2answers
980 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 ...
0
votes
1answer
1k 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] => ...
0
votes
1answer
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 ...