Obtaining values from objects

The problem with your use of foreach (in both cases) is that you are erasing any previous value $Comments or $CommentDates had before the current iteration. Rather than setting the value to the variable itself, perhaps you should be appending new values onto the variable as an array: // Not sure what purpose your $cake … Read more

Inefficient Query Confusion

…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, (SELECT CAST(meta_value AS DATE) FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = meta.post_id AND meta_key =’artist_talk_time’) … Read more

Query posts using custom taxonomy and selected terms

You’re using a deprecated method of querying by taxonomy. Read the Codex and use tax_query: $args=array( ‘post_type’ => ‘book’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘caller_get_posts’=> 1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘facts’, ‘field’ => ‘slug’, ‘terms’ => ‘information’ ) ) ); FYI, caller_get_posts is also deprecated.

Get categories names as an array to use it in theme settings

Thanks Michael for the tip. I finally got it. The solution is as follows: $options[] = array( “section” => “zzz”, “id” => HS_SHORTNAME . “_multicheckbox_inputs”, “title” => __( ‘Multi-Checkbox’, ‘hs_textdomain’ ), “desc” => __( ‘Some Description’, ‘hs_textdomain’ ), “type” => “multi-checkbox”, “std” => ”, “choices” => my_list_cats() ); And in functions.php: function my_list_cats() { $cats … Read more

Error while setting role

You have to use just $current_role variable instead of $current_role[0], because call get_user_meta( $author->ID, ‘wp_capabilities’ ); will return you array with roles as keys. <?php add_action( ‘save_post’, ‘update_roles’ ); function update_roles( $post_id ) { if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return $post_id; // Get the author $author = wp_get_current_user(); // Set variables for … Read more

How to use array in function to get only value I want

There’s wp_list_pluck() to get certain fields out of arrays or objects: $object = new StdClass(); $object->foo = ‘Hi!’; $object->bar=”Yo!”; $array[‘foo’] = ‘Hi!’; $array[‘bar’] = ‘Yo!’; $result_obj = wp_list_pluck( $object, ‘foo’ ); var_dump( $result_obj ); // Result: string (3) Hi! $result_array = wp_list_pluck( $array, ‘bar’ ); var_dump( $result_array ); // Result: string (3) Yo!

Saving array keep adding length of array

update_post_meta is maybe_serialising. And in this case is storing it as a serialised string The string your passing isn’t a correctly serialised array. If you pass it the raw array it will self convert it to the correct serialised string. The correct string is a:1:{i:0;s:4:”test”}, passing that shouldn’t serialise but probably will. You are betted … Read more