Tag Info

Hot answers tagged

12

I created a Kint plugin that works really well. I also integrates with the Debug Bar plugin. You can download it at: http://wordpress.org/extend/plugins/kint-debugger/ There are a few functions to help you out with WordPress specific globals: dump_wp_query() dump_wp() dump_post() For printing arrays in a styled, collapsible format you would do the ...


6

You can install and use Krumo with WordPress (or any php app really). there's the Hikari Krumo plugin that simplifies use, though check the comments there, there's an error that you'll need to manually fix to get it working with latest WP. There's also the WordPress Debug Bar plugin which you might find useful. EDIT- Another option I've recently discovered, ...


5

Use unserialize() to convert it into an array. $mydata = 'a:5:{s:9:"engine_id";a:1:{i:0;s:9:"300000225";}s:15:"transmission_id";a:1:{i:0;s:6:"257691";}s:5:"plant";a:1:{i:0;s:23:"Oshawa, Ontario, Canada";}s:15:"Manufactured in";a:1:{i:0;s:6:"CANADA";}s:22:"Production Seq. Number";a:1:{i:0;s:6:"151411";}}'; $mydata = unserialize($mydata); echo ...


5

For this kind of stuff, I wrote REF (requires PHP 5.3). Among many other features, it displays contents of DocBlock comments and linkifies PHP-internal classes, methods and functions (links point to the PHP manual). It also handles WordPress functions (links point to queryposts.com). Here's the output of $GLOBALS at the setup stage of WordPress in HTML mode ...


4

Assuming this array for example usage: $options = array( "name" => __('Font','mytheme'), "desc" => __('Change the font face)','mytheme'), "id" => "mytheme_font", "std" => array('size' => '10px', 'face' => 'Arial', 'color' => '#000000'), "type" => "text", ); For question 1, to reference nested arrays, just ...


4

I'm not sure you understand the logic of WP_Query. Rather than explain in words, here's a code example; $query = new WP_Query( array( 'meta_key' => 'Old ID', 'meta_value' => $atts['oldid'] ) ); if ( $query->have_posts() ) return $query->posts[0]->post_title; return ''; Check out the codex on interacting with WP_Query. UPDATE: To use ...


4

Filters work by calling each of the hooked callback functions (in priority order). The value to be filtered is passed to the first callback funtion. The returned value of that callback function is then passed to the second callback, and the returned value from that is passed onto third and so on, until all hooked callbacks have been fired. Whatever the last ...


4

My suggestion is to store the workouts as a new entry inside the particular user's meta data. » Saving a single workout Suppose the workout consists of the exercise IDs 1, 3, 5, 9. Then the code is: // this is the current workout $workout = array(1, 3, 5, 9); // get the current user $user = wp_get_current_user(); // update the user's meta data ...


3

this should do it: $categories = get_categories(); foreach( $categories as $category ) { echo '<input type="checkbox" name=' . $category->slug . '" value="' . $category->term_id . '" /> ' . $category->name . '<br />' . "\n"; } and you can change/order the list by feeding arguments to get_categories(): ...


3

Have you tried... <input type="text" name="my_options[option1]" value="<?php echo $options['option1']; ?>" /> <input type="text" name="my_options[option2]" value="<?php echo $options['option2']; ?>" /> <input type="text" name="my_options[option3]" value="<?php echo $options['option3']; ?>" />? I should say though ...


3

You can just assign a new value to the 1h_userbadge_comments25 key. Like so... <?php $meta_value = get_user_meta($user_id, 'lh_userbadges', false); // just assign this key a new value $meta_value['lh_userbadge_comments25'] = 25; Then just save it again. <?php update_user_meta( $user_id, 'lh_userbadges', $meta_value ); Whether or not storing all ...


3

I'm pretty sure if you switched to get_terms or similar you could return the data as an array and have no need to loop over it and build the array. However, having said that(and to save me going to check the docs), you can do it like so.. $categories = get_categories(array('taxonomy'=>'projects_category', 'exclude'=>7, 'orderby'=>'id')); if ( ...


3

There is no filter to change that behavior, you would have to replace the entire metabox. On the other hand: I think there is no really simple way to show and to save those arrays. Example for a fictive meta key 'foo': array ( 0 => 2, 'hello' => array ( 0 => 2, 'hello' => 'world' ) ) Creating a default interface ...


3

wpdb's get_results method takes an optional second argument that let's you specify out the data is return the default is an object. But you can also set it to... OBJECT - result will be output as a numerically indexed array of row objects. OBJECT_K - result will be output as an associative array of row objects, using first column's values as keys ...


2

General idea would be to loop through all attachments to retrieve, modify and write back their meta. Something like this (test thoroughly before using on anything important): $posts = get_posts(array( 'post_type' => 'attachment', 'numberposts' => -1, )); foreach( $posts as $post ) { // retrieve data, unserialized automatically $meta ...


2

extend this line: <?php if (is_page(array('page-one', 'page-two', 'page-three','page-four'))) $logo_image = 'subLogo.jpg'; with || is_category(array('cat-1', 'cat-2')) so you get, for example: <?php if (is_page(array('page-one', 'page-two', 'page-three','page-four')) || is_category(array('cat-1', 'cat-2')) ) $logo_image = 'subLogo.jpg'; ...


2

Don't serialize the search value, just use 'value' => '2011-09-16' 'compare' => 'LIKE'. Otherwise you're essentially looking for; a:1:{i:0;s:10:"2011-09-16"} Which of course doesn't actually match anywhere in; a:2:{i:0;s:10:"2011-09-16";i:1;s:10:"2011-09-17";}


2

I'd suggest not using $query_string to simplify things. If you're using an array, stick with the array form for the query variables: global $wp; $paged = ((int)get_query_var('paged')) ? (int)get_query_var('paged') : 1; $s_array = array( 'post_type' => 'blog', 'caller_get_posts' => 1, 'paged' => $paged, 'meta_query' => array( ...


2

Use the php function unserialize() on that string and you will get a proper array. $cats = get_cats_from_database(); $cats = unserialize($cats); //now $cats is an array like Array(0 => 20, 1 => 343 );


2

As @Ashfame as already pointed out, you shouldn't store defaults in the database - that should be for user selected options (of course, if they select the defaults, then fine - store them :). However, you don't need to use wp_parse_args() either. get_option allows you to select a default value. For instance: //If nuod_logo is not found, uses 'newlogo.pnp' ...


2

This is important which most of the people don't get right. Don't save the defaults in the database. You should be using wp_parse_args() for this purpose. $defaults = array ( 'logo' => 'http://domain.com/logo.png', 'do_extra_thing' => false ); // Parse incomming $args into an array and merge it with $defaults $options = wp_parse_args( ...


2

The following should do it: function get_hidden_cats() { $my_cats = get_option('ce4_category_fields'); $my_hidden_cats = array(); foreach( $my_cats as $cat_id => $cat_attrs ) { if( 'true' == $cat_attrs['my_cat_hide'] ) $my_hidden_cats[] = $cat_id; } $my_hidden_cats = implode( ',', $my_hidden_cats ); return ...


2

...or try this: // ... put your $today and $future variables here... global $wpdb; $events = $wpdb->get_results( " SELECT * FROM {$wpdb->posts} LEFT JOIN( SELECT DISTINCT post_id, (SELECT CAST(meta_value AS DATE) FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = meta.post_id AND meta_key ='opening_time') AS opening_time, ...


2

Also you can use the plugin Debug Objects; list also scripts and styles. The Plugin has many more options for dev and debugging, but also this feature. Alternative is this source, you find informations and the post about this topic here: add_action('wp_footer', 'fb_urls_of_enqueued_stuff'); add_action('admin_footer', 'fb_urls_of_enqueued_stuff'); function ...


2

Why not just use xdebug? Looks pretty neat to me, by default. There is also Kint, http://code.google.com/p/kint/ but I found the dropdowns more confusing, then the full output of xdebug.


2

Add meta data as "flat" data to the post The actual problem is, that your meta data comes back as array (with a single entry), when calling get_post_custom( $id ); for your post. Here's a simple function, that adds all meta data attached to a post to your post object. /** * Merges custom/meta data with post data * 1) get_post_custom() is cached from the ...


2

Definite solution: Seeing as wp's core get_post_custom function returns multiple data fields saved as a single key in a random order, I resolved the issue by writing a function to replace it - which has some added flexibility: /*--------------------------------------------------------------- Function: Retrieve post meta field for a post based on ID ...


2

once you have set of result in particular order you can achieve it simply as below : - $pageposts=$wpdb->get_results(" SELECT * FROM $wpdb->posts WHERE post_type='post' AND post_status='publish' ORDER BY post_date DESC LIMIT 6 ", OBJECT); First time $i=1; foreach($pageposts as $pageposts_first){ //here ...


2

I figured out what I was doing wrong. A simple beginners mistake. Array_reverse was working properly, but I wasn't then reassigning the reversed array back to the $home_shows WP_Query, hence not seeing any change. Here is the answer, and my revised code. <?php $args = array( 'post_type' => 'show', ...


2

Steve you're doing it wrong. WordPress provides Settings API that should be used for settings pages. If you aren't familiar with Settings API see great tutorial by Chip Bennett - Incorporating the Settings API in WordPress Themes.



Only top voted, non community-wiki answers of a minimum length are eligible