Custom Blog Loop on Home Page

don’t use query_posts() for secondary loops – When should you use WP_Query vs query_posts() vs get_posts()? get only top level categories using ‘category__in’ should not get posts from child categories for example: <?php $cats = get_categories(‘parent=0’); foreach ($cats as $cat) : $args = array( ‘posts_per_page’ => 1, ‘category__in’ => array( $cat->term_id ) ); $top_cat_query = … Read more

Get Posts by IDs (optionally)

It looks like WordPress doesn’t ignore empty post__in param. So you’ll have to do this yourself like this… $ids=”1,2,3″; if ( $ids ) { $arr = explode(“,” ,$ids); $args = array( ‘posts_per_page’ => $number, ‘post__in’ => $arr ); } else { $args = array( ‘posts_per_page’ => $number ); }

current-user_can not working in loop

From Codex : Do not pass a role name to current_user_can(), as this is not guaranteed to work correctly (see #22624) Instead, you may wish to try the check user role function put together by AppThemes. I would propose to use is_user_logged_in() to check your function.

Looping through custom taxonomy and display custom post types (Custom Post Type UI)

Try this, this should retrieve all taxonomies terms including empty ones. <?php $terms = get_terms(‘price_types’, array( ‘hide_empty’ => false, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ) ); echo print_r($terms); foreach( $terms as $term ): ?> <section class=”pricing”> <h2><?php echo $term->name; ?></h2> </section> <?php endforeach; ?>

Compare Two Custom Post Types Using The Same Custom Taxonomy

Don’t use get_the_term_list() as it returns an HTML string, which makes comparing more difficult. Use wp_get_post_terms() (Codex link) instead. It can return an array, and then you can use something like array_intersect() to get the terms that match. Your code should look something like this (I haven’t tested this): $course_terms = wp_get_post_terms($course_post_id, ‘course_type’. array(‘fields’=>’slug’)); $testimonial_terms … Read more

How to add ASCII symbol after each recent post [closed]

Are you talking about (something like) this: <?php $args = array( ‘numberposts’ => 2, ); $recent_posts = wp_get_recent_posts($args); foreach ($recent_posts as $recent) { ?> <li> <a href=”https://wordpress.stackexchange.com/questions/127441/<?php echo get_permalink($recent[“ID’]); ?>” title=”<?php echo esc_attr($recent[“post_title”]); ?>”> <?php echo $recent[“post_title”]; ?> </a> &gt; </li> <?php } ?> If so, what was the problem?