janemig
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: How to query a speaker based on a conditional taxonomy queryAnyone??
Forum: Fixing WordPress
In reply to: How to query a speaker based on a conditional taxonomy queryDo I need to create a taxonomy template file, i.e. taxonomy-event-names.php? And if so, what goes in it?
Forum: Fixing WordPress
In reply to: How to query a speaker based on a conditional taxonomy queryHere is my speakers query statement, in case I need to ‘blend’ anything into it:
<?php $temp = $wp_query; $speakers = new WP_Query( array( 'post_type' => 'speakers', 'paged'=>$paged, 'orderby'=>'title', 'order'=>'ASC' ) ); ?> <?php if ( $speakers->have_posts() ) : while ( $speakers->have_posts() ) : $speakers->the_post(); ?>
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsAnd, to the moderator who opened up the wonderful world of ‘new WP_Query’ to me. Give a man a fish and he’ll eat for a day. Give a man a fishing pole and he’ll eat for a lifetime. Thanks for the fishing pole, Alchymyth.
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsWhich, of course, leads me to the query: How can you nest a loop of a custom post that HAS an archive into another loop? Sigh. This may be a query for another day…
Nonetheless, here is the final code, I hope it can help anyone who’s in a jam:
<?php /** *Template Name: Single Events */ ?> <?php get_header(); ?> <div> <?php if ( have_posts() ): ?> <?php while (have_posts()) : the_post();?><!-- begin events loop --> <article> <!-- Events content here --> <!-- Then query for Speakers: --> <?php $temp = $wp_query; $speakers = new WP_Query( array( 'post_type' => 'speakers', 'paged'=>$paged, 'orderby'=>'title', 'order'=>'ASC' ) ); ?> <?php if ( $speakers->have_posts() ) : while ( $speakers->have_posts() ) : $speakers->the_post(); ?> <div class="speakerbio clearfix" id="post-<?php the_ID(); ?>"> <div class="left"> <a href="<?php esc_url( the_permalink() ); ?>"><?php the_post_thumbnail(); ?></a> </div> <div class="right"> <h3><?php the_title(); ?> <a href="#top"><i class="fa fa-caret-up"></i></a></h3> <div class="sptitle"><b><?php the_field('speaker_title'); ?></b></div> <?php the_field('speaker_bio_text'); ?> </div> </div> <!-- END speakerbio --> <?php endwhile; endif; $speakers->reset_postdata(); $wp_query = $temp; ?> <!-- End speaker query and reset the events post data--> <!-- Events content here --> </article> <?php endwhile; ?> <?php endif; ?> </div> <?php get_footer(); ?>
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsI found the answer! The ‘speakers’ custom post type declared Has-Archive as True, but it should be FALSE because it’s only being displayed on the events page as a list! So I changed has archive to false and it works!
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsOk, I realized that placing that query code into the single-events.php only made it query the event posts all over again and return the latest 1. Thus, my getting only 1 post (the latest one) on that single page. So I took it out.
And what I’m still left with is figuring out why the nesting of the speakers loop isn’t returning speakers, but is returning a list of my other custom posts and pages, with the styling of the speakers custom post type. Does that shake anything loose?
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsHold the phone! I just added a few events and when I click any one of them to get to the main event page, only the last post that was created displays, no others. I tried adding wp_reset_query() at the end of the single-events.php page, but it doesn’t resolve it. Any clues?
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsYay, I found the missing piece of code. I put this query right before my original loop and voila it all works! Here’s the code for anyone who’s in a jam:
<?php query_posts(‘post_type=events&posts_per_page= -1’); ?>
(you would substitute ‘events’ with whatever your custom post type name is. Use that with the wonderful code that wonderful Alchymyth was so generous to provide and you’re off and running with nested custom loops! Woohoo!
Many thanks again to you, Alchymyth!!!
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsDo I have too many endifs and endwhiles in there? I’ve tried every combination, taking each out one by one, repositioning them, etc. Should the original query be something other than an ordinary loop?
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsAlso, how would I get the speakers nav menu to display in alphabetical order?
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsNote, it uses loop code from the Advanced Custom Fields plugin. Could that be conflicting? Actually, I tried taking that code out, but it didn’t fix it.
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsHi Alchymyth,
It is ‘speakers’.
I just put the code in pastebin: https://pastebin.com/gCYZBNuw
This is a custom build, using Starkers foundation as a base. It’s very pared down. Do you need the archive-speakers.php or single-speakers.php code?
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsThat seems so perfect!! You are so kind to help! I’m using the code and it’s still not behaving. It’s actually puling in a different custom post type, not speakers, which is odd. Question: I created an archive-speaker.php and a single-speaker.php for the cpt, Is that interfering in some way, should I not include those files since I’m only placing the speakers on the events page?
Forum: Fixing WordPress
In reply to: Nesting Custom Post Type LoopsThanks so much, I tried it but it’s not working. It makes total sense though! Does the first loop have to use WP_Query as well?