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


7

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


7

WP has a lot of nifty functions in the corners for such stuff. Try this: if ( !empty( $categories ) ) { $excluded_categories = wp_list_pluck( $categories, 'term_id'); $excluded_categories = implode(',', $excluded_categories); }


6

<?php if(count($related)) { echo "<div>Read More<ul>"; foreach($related as $id) { echo '<li><a href="'.get_permalink( $id ).'">'.get_the_title( $id ).'</a></li>';     }     echo "</ul></div>";   } ?>  


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

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


5

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


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


5

I am not going to give any specific code but I will give you Idea how it can be done without creating any custom database table. I am assuming one driver per truck Algorithm Create two html list, make them sortable. Each list items represents a post type and have ID data field. Once sorting is done get all ids in order. Make two array one contains truck ...


4

You are overwriting $post_ids variable on every while loop, never collecting them. That can be solved using $post_ids = array(); while (have_posts()) : the_post(); $post_ids[] = get_the_ID(); endwhile; var_dump($post_ids); // this is an array of ids However there is simpler way, you can skip the whle cycle and simply run: if( function_exists( ...


4

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


4

bloginfo() is using echo, you need a function that returns its value: get_bloginfo(). In this case you could also use just the function get_bloginfo() is using: get_template_directory_uri().


4

No, this won't work: <?php echo get_option('notice_data[Message]'); ?> Because get_option pulls whole option value by option_name, it doesn't pull by pieces of the serialized array. What you are asking for is a key (option_name) called literally notice_data[Message]. Assuming you've saved the option as notice_data you aren't going to get a match, ...


4

array_merge does not work the way you expect/need it to, but honestly I am not sure why you are making this so complicated. All you need is: $args = array( 's' => 'keyword1 keyword2', 'orders' => 'DESC', 'showposts' => 60 ); // var_dump($args); // debug $query = new WP_Query($args); var_dump($query->request); // debug The ...


4

You have to collect multiple fields under the same name like this … name="collect[1]" name="collect[2]" … and adjust your widget logic to this. Here is a very simple demo widget: <?php # -*- coding: utf-8 -*- /* Plugin Name: Store Options as array */ add_action( 'widgets_init', array ( 'T5_Array_Options_Widget', 'register' ) ); class ...


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


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

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


4

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


3

$mytimestamp = date(get_option('date_format'), strtotime($date)) . ' at ' . date(get_option('time_format'), strtotime($date));


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

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

I suspect you just want to see the content of the array for dev purposes, in which case s_ha_dum's suggestions of print_r( $mpdata ) or var_dump( $mpdata ) should suffice. To output the content of the array as a string (assuming it is not multi-dimensional) you could just echo implode( ', ', $mpdata ).


3

This is a serialized value, so you should run it through maybe_unserialize() or just unserialize() before you edit it. When you work in plugins or themes, always use the API: update_option() and get_option() for example. These functions will un/serialize the values for you, so you don’t have to worry about the database. See also: Settings API with ...


3

$args = array( 'post_type' => 'testimonials', 'posts_per_page' => 4, 'orderby' => 'post__in', 'post__in' => array(883, 563, 568, 106); ); Using post__in within the orderby value it will honour the order of the array of IDs passed in post__in


3

get_user_meta() with omitted key argument will return all data for the object. Trying to retrieve metadata selectively is usually pointless optimization from performance point of view, since everything built on Metadata API tends to just query all data anyway and cache it (which in turn object cache plugin makes persistent and snappy).


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

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

if you fix your date format to be yyyy-mm-dd they'll just naturally order themselves and you won't have to do all this complicated output.


3

Use get_posts instead - You can use the function get_posts() to get all the posts as array. This function accepts almost all parameters that of query post's. Example - $args = array( 'numberposts' => 3,'category' => 3 ); $homePost = get_posts( $args ); $one = $homePost[0]; $two = $homePost[1]; $three = $homePost[2]; ...



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