How To Loop Through list with Custom Post Types

Maybe this could be useful. I used it on my own site to display a list of thumbnails. <?php // check if there’s a thumbnail if ( has_post_thumbnail($post->ID)) { //show thumbnail echo ‘get_the_post_thumbnail($post->ID, ‘thumbnail’ , array(‘class’ => “img-responsive yourClass”)); } else { //show another image if there’s not a thumb echo ‘<img class=”img-responsive” src=”‘.get_template_directory_uri().’/MISSING-PHOTOS.jpg”>’; } … Read more

How to execute custom loop before loop content?

Try using the genesis_before_content hook. add_action(‘genesis_before_content’, ‘gt_custom_loop’); function gt_custom_loop() { // this gets executed after the page content, how to make it execute before? }

Cant pull in featured Image

You won’t get anything back from your template simply because the loop returns what is in the main query object for that specific page. To see what is actually in the main query object, you should do var_dump( $wp_query ); outside the loop. To display custom content on a page template, you will need to … Read more

Querying multiple categories in the WP loop if one of the category IDs is dynamically obtained

So, I think I’ve got it figured out… …get_cat_ID didn’t seem to be the correct function. I swapped it out with get_category_by_slug and that eventually got it up and running. //LINK IN BLOG POSTS THAT MATCH CHAPTER SLUG function chapter_posts() { //Get Group Slug $postCategory = bp_get_current_group_slug(); //Get posts global $post; $chapterCatID = get_category_by_slug($postCategory)->term_id; $args … Read more

Problems with WP_Query, Loop, a condition and Posts per Page

Just for your Info. I switched my Plugin to Advanced Custom Fields and created the Query like this. Maybe it was because of the “-” I used in my CustomField or it was the format of my Date. $today = date(‘Ymd’); $args=array( ‘post_type’ => ‘veranstaltungen’, ‘posts_per_page’ => 3, ‘meta_query’ => array( array( ‘key’ => ‘ende’, … Read more

Loop doesn’t work

This should work (if your post_type is not post you will need to amend the code) <?php $args = array( ‘post_type’ => ‘post’, ‘cat’ => ’31’, ‘posts_per_page’ => 5, ); $query = new WP_Query( $args );?> <?php if( $query->have_posts() ) : ?> <?php while( $query->have_posts() ) : $query->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/209558/<?php the_permalink(); ?>”><i class=”fa fa-book”></i> … Read more

Category page shows only 1 post when that post has more than 1 category?

Multiple Loops Outside the loop you can get available terms of the core taxonomy category with get_terms( ‘taxonomy_name’ ). The resulting array contains objects like object(stdClass)#141 (9) { [“term_id”] => string(1) “3” [“name”] => string(9) “The Name of your Category” [“slug”] => string(9) “name-of-tax-term” [“term_group”] => string(1) “0” [“term_taxonomy_id”] => string(1) “3” [“taxonomy”] => string(11) … Read more

enumerating custom taxonomies?

get_tags is just a wrapper around the more general taxonomy function get_terms. So you’ll get the result you need with this: function execute_taxography() { $wpbtags = get_terms( ‘books’ ); $output.= ‘<div class=”grid”><div class=”taxography-grid”><ul>’; foreach($wpbtags as $tag) { $output.= ‘<li class=”item”><a href=”‘. get_term_link($tag->term_id, ‘books’ ) .'” style=”background-image: url(\’http://localhost/wordpress/wp-content/uploads/tags/’ . $tag->slug . ‘.png\’)”><span class=”count”>’. $tag->count .'</span><span class=”taxography-name”>’. … Read more