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

How to create a multidimensional array with multiple loops

I don’t think this is a restrict WordPress question, but you might try $args = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘work’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ); $data = array(‘work’ => array()); $loop = new WP_Query($args); if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post(); $id = $loop->post->ID; $attachments=array(); if(get_field(‘work’)): while(has_sub_field(‘work’)): $attachment_id = get_sub_field(‘image’); $caption … Read more

Turn get_posts as string into an array for use in theme admin options

This… array(’54’=>’Post #1′,’23’=>’Post #2′, ‘654’=>’Post #3′,) … is not a string. It is an array definition. All you need to do is create an array, which is what you want, and skip the string completely. function post_page_options(){ $post_page_options = get_posts(‘category=orderby=title&order=asc&numberposts=”); foreach( $post_page_options as $value ) : $str[$value->ID] = $value->post_title; endforeach; return $str; }

Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?

Couple points: The customize_register action hook actually passes your function the $wp_customize variable, you don’t need to declare it as the global. Just put it as the first argument in your function declaration. The reason your code doesn’t run on the front end of the site is that the customize_register action hook only runs when … Read more

Getting a specific value out of array using get_attached_media

Don’t use the GUID. Despite appearances, that isn’t an URL. Use wp_get_attachment_image_src. Something like: $image = wp_get_attachment_image_src($post_id,’full’); echo $image[0]; Or use wp_get_attachment_url with the post ID. $image = wp_get_attachment_url($post_id); Of course, I don’t know what the actual variable name is that holds your images but you should see the ID in the post objects and … Read more

How can I access specific posts brought back by query_posts?

Why not just use a counter and then conditional logic? $i = 0; while($loop->have_posts()) : $loop->the_post(); if($i === 0){ echo ‘<div class=”a”>’.other_stuff().'</div>’; } elseif($i === 1){ echo ‘<div class=”b”>’.other_stuff().'</div>’; } else { echo ‘<div class=”default”>’.other_stuff().'</div>’; } $i++; endwhile;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)