Combine two foreach Arrays into one table row

if the artist names and track names are in matching order and the same in number then: <?php $artists = get_post_custom_values(‘Artist’, $post->ID); $tracks = get_post_custom_values(‘Track’, $post->ID); $i=0; foreach ( $artists as $key => $value ) { $class = ( $i % 2 ) ? ‘alternative’ : ”; // modulus operator echo ‘<li class=”‘ . $class … Read more

SQL query add only posts with custom field to array

Why don’t you just do: <?php global $post; $args = array( ‘post_type’ => ‘post’, ‘post_status’ = ‘publish’, ‘posts_per_page’ => ’10’, ‘meta_query’ => array( array( ‘key’ => ‘fruit’, ‘value’ => ‘apple’ ) ) ); $custom_query = new WP_Query( $args ); while( $custom_query->have_posts() ): $custom_query->the_post(); ?> <?php the_title(); ?> <?php endwhile; wp_reset_query(); ?>

Extract array from custom field

This is mostly pure PHP, but you need to implode the array. add_shortcode(‘bundled_ids’,’bundled_ids_func’); function bundled_ids_func() { $meta_values = get_post_meta( get_the_ID() , ‘_bundled_ids’, true ); if (!empty($meta_values)) { $mydata = implode(‘,’,$meta_values); // add this line return $mydata; } }

Populate checkboxes from array

Use the following function to make check-boxes for taxonomies: function get_terms_chekboxes($taxonomies, $args) { $terms = get_terms($taxonomies, $args); foreach($terms as $term){ $output .= ‘<label for=”‘.$term->slug.'”><input type=”checkbox” id=”‘.$term->slug.'” name=”‘.$term->taxonomy.'” value=”‘.$term->slug.'”> ‘.$term->name.'</label>’; } return $output; } echo get_terms_chekboxes(‘country’, $args = array(‘hide_empty’=>true)); Hope this will help you!