merging an array to an existing array using add_filter

You are overwriting $args in add_yourself_to_some_examplehook(). Based on what you’re saying you want to achieve, you should be appending the new item instead: add_filter( ‘some_example_hook’, ‘add_yourself_to_some_examplehook’ ); function add_yourself_to_some_examplehook($args) { $args[ ‘Hello5’ ] = ‘HELL4’; // <– Note the syntax here. return $args; }

Show post only if match all categories

Here’s an updated version of your code that will get posts that have the Post Format Video and that have the same Categories as the current post in the loop. You’ll call wpse_get_video_posts_with_matching_categories() to execute the function. function wpse_get_video_posts_with_matching_categories() { $categories = get_the_category( get_the_ID() ); if ( empty ( $categories ) ) { return; } … Read more

Sort a custom post type array numerically

get_terms function will return an array of object. Each of them has term_id field which contains id of a term. Just use it instead of slug and you will have what you need: <?php $terms = get_terms(“ratios”); if ( $count($terms) > 0 ){ foreach ( $terms as $term ) { echo “<option value=”” . $term->term_id … Read more

wp_nav_menu show 1 item only

Why would you only want to display one item from a menu of many items? You can create additional menus by registering them in your functions.php file and then associating then in the Appearance -> Menus area of the WP-Admin. http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

Serialized array, grab specific posts with meta_key/meta_value[0]->is_featured

It is possible if you shape your meta query to look for the serialized string like this, assuming your array value is always an integer: $params = array( ‘meta_query’ => array( array( ‘key’ => ‘mediSHOP_product_extras’, ‘value’ => ‘s:11:”is_featured”;i:1;’, ‘compare’ => ‘LIKE’ ) ) ); $query = new \WP_Query( $params ); If the array value is … Read more

How to update serialized post meta?

You must read custom field themeOps first, update index option3 in array and then save/update whole array. $kisiArray = get_post_meta( $post_id, ‘themeOps’ ); $kisiArray[‘option3’] = ‘peach’; update_post_meta( $post_id, ‘themeOps’, $kisiArray ); Update (sort by custom field) $args = array( ‘post_type’ => ‘post’, ‘meta_key’ => ‘themeOps_option3’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ); $query = new … Read more

Passing array of strings to a SQL statement in a WordPress plugin

$wpdb->prepare() accepts a single array of arguments as the second parameter, e.g. $wpdb->prepare( “SELECT * FROM table WHERE field1 = %s AND field2 = %d AND field3 = %s”, array( ‘foo-bar’, 123, ‘[email protected]’ ) ) Therefore you can use an array of placeholders with the SQL command (the 1st parameter), like so: // Create an … Read more