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 ...

learn more… | top users | synonyms

6
votes
6answers
4k views

Nice way to print_r arrays

So you know how Drupal has functions in modules like Devel that allow you to output arrays in a nice format like dsm($array) or krumo($array)... Does WordPress have an equivalent or a nice way of ...
5
votes
1answer
2k 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 ...
5
votes
2answers
364 views

Why does get_users suddenly return duplicates?

I'm having a hard time figuring this one out. I'm running a simple users query : $args = array( 'role' => 'custom_role', 'orderby' => 'ID', 'order' => 'DESC', 'number' => ...
4
votes
2answers
7k views

How to get permalink and title from post ID?

I have stored an array of post IDs and I would like to list the posts as links, meaning I need to get the title and permalink for the post ID - $id. The list should be echoed out by the following if ...
4
votes
1answer
821 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( ...
4
votes
1answer
338 views

How can I save an array from a random post sequence for later use?

I'm building a random workout generator on Wordpress to help with my fitness, and am stuck at saving random post arrays for later reference. I'll explain. The generator should work in two main ...
3
votes
2answers
4k views

What kind of object type is WP_Query?

I am getting this error when I try to return the post_title value from my WP_Query: **Fatal error:** Cannot use object of type WP_Query as array Here is the code: $query = new WP_Query( array( ...
3
votes
3answers
2k views

Reversing the order of posts AFTER the query is performed

I'm am displaying the last 5 posts of a custom post type 'show'. This gives me the latest post first. <?php $args = array( 'post_type' => 'show', 'posts_per_page' => 5, 'order' ...
3
votes
2answers
870 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" => ...
3
votes
2answers
386 views

How do I pass an array as an argument to a WP-CLI command?

I want to use WP-CLI to create some new posts with custom taxonomy terms assigned. The challenge is that wp_insert_post's tax_input argument only accepts arrays, which I would have to specify on the ...
3
votes
1answer
55 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 ...
3
votes
1answer
750 views

Settings API - save an array of options as one setting (array_push?)

1. Basic settings API callback. Using Settings API my $sanitize_callback validating function looks like: (...) if($type == "foo") { $valid_input[$id] = $option[$id]; } else ...
2
votes
2answers
777 views

Save custom post type in different table

I need to store custom post type post data into a custom table, not in wp_posts and wp_postmeta. Is it possible? anyone help please. Actually, I have created two custom post type named "truck" and ...
2
votes
1answer
5k views

Fetch array with $wpdb

I am trying to convert this code to use the $wpdb. $data = array(); $query = "SELECT * FROM videos"; $query_exec = mysql_query($query) or die(); while($row = mysql_fetch_array($query_exec)) { ...
2
votes
1answer
149 views

How to use bloginfo( 'template_directory' ) in array

I want to pass bloginfo( 'template_directory' ) in an array I tried this but not working. How to write it correctly? <?php get_the_image( array( 'size' => 'full', ...
2
votes
1answer
357 views

How do I update a specific object in an array, in user meta?

I have this array, below, to set custom user meta (lh_userbadges) in user_meta but I'm not exactly sure how to update just parts of the array later on... $lh_user_badges = array( ...
2
votes
2answers
152 views

WP_User_Query order by meta_key that is an array

I have set a user metadata named achievements which is an array containing various numeric values. Using WP_User_Query, I want to order the list by a specific key within this array named points. The ...
2
votes
2answers
235 views

Automatically adding meta data to posts or multiple query help

I run an events company whose website uses a custom post type system for posts (blog), events and tickets all stored as CPT's in the DB. On the guestlist (which counts 'ticket' custom posts if the ...
2
votes
1answer
442 views

Formatting of curly brackets array from WP database to get more readable output

E.g. when I want to edit something in my WP database, I get a headache, literally. Because I see something like this: ...
2
votes
1answer
269 views

WP doesn't show Array Custom Fields?

I'm wondering why WordPress doesn't list PHP array() and any serialized data in Custom Fields in Admin Panel (for Pages, Posts etc.)? Only Custom Fields containing strings and numbers show up and can ...
2
votes
1answer
4k views

Can I query custom meta data through WP_Query

Ok, my question is a bit complex so I will try and give a general explanation and then go into details afterward. I am running WordPress 3.4.2 and I am using WCK Post Type Creator and WCK Custom ...
2
votes
1answer
182 views

Sort a custom post type array numerically

We've set up drop down lists to allow people to filter posts based on custom post types. In order to populate the drop down list I am using: <?php $terms = get_terms("ratios"); $count = ...
2
votes
1answer
752 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 ...
2
votes
2answers
355 views

wp_nav_menu show 1 item only

I was reading Wordpress documentation and also trying to find some clear example of how to do this but I couldn't, sorry if this is posted elsewhere but I did my best trying to find an answer before ...
2
votes
3answers
3k views

Add post title as alt tag for featured image

How do I add post title as alt tag in a post? I tried using array(title => '.the_title.') but it didnt work. I think I am not suppose to use the_title. I tired using get_the_title as well. Thanks
2
votes
1answer
575 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
1k views

Problem with wp_update_post

I'm trying to write a plugin that creates a page if a box is checked (value 1) and if the post id doesn't already exist. If the post id does already exist, then I want to update the post with whatever ...
1
vote
1answer
7k 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" ...
1
vote
2answers
2k views

Order by & include array by specific post ids

I have the following: <?php $num_cols = 2; // set the number of columns here $args = array( 'post_type' => 'testimonials', ...
1
vote
1answer
274 views

How can I get an array of all IDs from the current queried object?

I am trying to join an array of post IDs together. Right now, it seems my code is creating a separate array for each ID, instead of one array with each ID. This is the code that I have come up with. ...
1
vote
2answers
480 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 ...
1
vote
2answers
3k 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!
1
vote
1answer
2k views

Working with an Array inside Your Theme Options Array - Multiple Values

I apologize if this is covered extensively elsewhere, I'm not sure how to phrase my searches on the topic. Basically, instead of the following standard code to store data in WP-options... $options = ...
1
vote
2answers
47 views

How to use IN array properly in Wordpress?

I have an array containting these values (including the apostrohpes): 'course_3202','course_3201','course_3200','course_3199' I try to fetch results from these values in postmeta-table. SELECT * ...
1
vote
2answers
5k views

Defining a global array in functions.php?

I try to create an array of years, which is avaible in my template-files and in at least one other function in the functions.php. function get_the_years() { global $year_arr = range(2001, ...
1
vote
2answers
560 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 ...
1
vote
1answer
55 views

Minimize database queries to user tables?

I'm trying to come up with a strategic way to collect large amounts of usermeta data (and output to the screen) while keeping database queries low. Some pages, like the home page, single pages, and ...
1
vote
1answer
64 views

Get specific custom field keys from a post and put into an array

I have the following code to look up the longitude and latitude based off of a custom field upon saving the post. My address fields (street_1, city and state) are separate. I have searched and thought ...
1
vote
1answer
149 views

My theme saves their custom post type's metadata as a serialized array, how to access the keys?

I've recently bought the WP Directory Portal theme from ThemeForest. Since the theme doesn't do frontend posting of custom post types, I've resulted to using WP User Frontend Pro. There's a problem ...
1
vote
2answers
1k 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 ...
1
vote
1answer
286 views

Simple custom theme option not being saved

I'm not a web developer and have been following a tutorial on how to add options to a simple self-written theme. In functions.php I've added the following code: <?php $themename = "Theme Name"; ...
1
vote
1answer
388 views

PHP get the first post separately from array returned by wpdb->get_results()

Apologies if the title isn't clear, can't quite think how to word this. I'm getting a pretty standard list of posts like this: $pageposts=$wpdb->get_results(" SELECT * FROM ...
1
vote
1answer
448 views

Passing Custom Field Data as Array to be Saved (Resulting Custom Field Array is inconsistent)

I've been staring at this for hours, and it's clear I'm missing something, but I don't know what it can be... I have custom meta box for adding downloads to a particular post or page. All the data ...
1
vote
2answers
3k views

Working with query_posts ( arrays and query strings)

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far. $paged = (get_query_var('paged')) ? ...
1
vote
1answer
2k views

tax_query operator woes

I am trying to filter posts by multiple taxonomies. My code below works great, but their is one thing I can't quite figure out. When I filter the posts it seems that they only show the posts that ...
1
vote
2answers
572 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
35 views

Return array keys and values

I am creating some options in the functions.php file. I created a function that gets input on the front end, puts the values into a new array and returns them to the front end. I am trying to figure ...
1
vote
1answer
29 views

How pass a 0 in $atts?

I need to pass an attribute (tabindex="0") into my navigation link. I use this filter: /** * Add tabindex attribute to menu links * * Brings keyboard accessibility for opera browser. */ ...
1
vote
3answers
92 views

get_*_meta doesn't always return an array

I find it annoying that functions like get_user_meta or get_post_meta will return an array if the meta key exists or false if it doesn't. This means I need to do a check like so: $meta = ...
1
vote
1answer
200 views

get_the_tags() not iterating through for/while loop, but will with foreach

I'm having a very peculiar issue with Wordpress right now that I can't understand, and hopefully someone here will have experience with it to help solve it. I'm trying to iterate through the array ...