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


8

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); }


7

<?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>";   } ?>  


7

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


6

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


6

You can use get_the_title() to return the current post title in the loop.


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


4

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


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

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


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

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

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


4

You are using an incorrect check here. is_singular() returns true when a post is from the specified post type or post types or the default post types when none is specified. You cannot target specific single posts with is_singular() You have to use is_single to target a specific post if ( is_single( 'post-a' ) { // Do something for post-a } elseif ( ...


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


3

While I am a big fan of tweaking wordpress as much as it could because it allows us to, I think the best way forward is to have the best algorithm before coding. Reading your question, I came across " Actually, I have created two custom post type named 'truck' and 'drivers' ". Issue: Linking two post types requires extra work as you are doing because ...


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

Searching inside a serialized array is difficult and inefficient-- ie. slow. The following pure SQL will do it: SELECT * FROM `wp_postmeta` WHERE `meta_key` LIKE 'daysonair' AND `meta_value` LIKE '%thursday%' LIMIT 0 , 100 Something like this should get WP_Query to do something similar: $args = array( 'post_type' => 'post', 'meta_query' => ...


3

When you are saving the multidimensional array you can use this code: $product_img_path[$count]['wpc_resize_thumb_img'] = $upload_dir['url'].'/'.$resize_img_name; $product_img_path[$count]['wpc_resize_bid_img'] = $upload_dir['url'].'/'.$resize_big_img_name; update_post_meta($post->ID, 'wpc_images', $product_img_path); That way you can get ...


3

Looking at your code you are calling the function ghoolo_mango() by using the the wp actoin hook. This is fine but be aware that it will add your post everytime a page loads. The problem is that you are also calling the function ghoolo_mango() within the function itself - i.e. it will keep calling it over and over. To fix the problem, remove the line ...


3

You are using get_option() wrong, first variant, so take another look at the get_option() documentation. Basically you can't directly access an array element with the function, it just doesn't support it. The second variant should be possible, but you need at least PHP 5.4 - if I'm not totally mistaken; I don't know anything about dreamweaver. The reason ...


3

You're looking at a serialized representation of the array Array( '75', '68' ). Serialization is the process by which PHP stores a data object as a string, much like the manner in which JSON is a string representation of a Javascript object. PHP data structures may be converted into a serialized format via PHP's serialize(), and back again using ...



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