• Resolved mmulwa

    (@mmulwa)


    Ok so here’s my issue.

    I have several pages that has multiple tabs on it. Each tab is aimed to grab content from different custom post types. Each post within those post-types are categorized by the page they will appear on.

    For example:

    Lisa has a page
    under she has 5 tabs, one for news, video, photos, etc.

    each of those tabs is a custom-post -type. The way the are to show up on the page is by selecting the ‘lisa’ category before publishing.

    I’ve run into an issue, I can’t figure out how to get each person’s category to up based on the page you are on. Basically, how do get the wordpress loop to change the category id to be the same as the category the page is on?

    Here’s the code:

    <?php query_posts( 'post_type=results' . '&cat=jessicaeye'); ?>
                	    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
                	    		<section>
                	    			<div class="result">
                	    				<header>
                	    					<h1>
                	    						<?php the_field('winloss') ?>
                	    					</h1>
                	    				</header>
                	    				<footer>
                	    					<h1>
                	    						<?php the_field('type') ?>
                	    					</h1>
                	    					<h1>Round</h1>
                	    					<h1>
                	    						<?php the_field('round') ?>
                	    					</h1>
                	    				</footer>
                	    			</div>
    
                	    			<div class="review">
                	    				<header>
                	    					<div class="back"></div>
                	    					versus <strong><?php the_field('opponent') ?></strong> on <?php the_field('date') ?>
                	    				</header>
                	    				<article>
                	    					<div class="back"></div>
                	    					<?php the_field('summary') ?>
                	    				</article>
                	    			</div>
                	    		</section>
    
                	    	 <?php endwhile; else: ?>
    
     							<p>Sorry, no posts matched your criteria.</p>
    
     						<?php endif; ?>

    Help would be very much appreciated on this subject.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Assuming you are on the page that has the category assigned, you should be able to get the category like this:

    <?php
    $cat = get_the_category();
    $cat_id = $cat->cat_ID;
    query_posts( 'post_type=results' . "&cat=$cat_id"); ?>
    Thread Starter mmulwa

    (@mmulwa)

    Hey vtxyzzy,

    First off, thanks for the reply.

    I tested the code that you posted and it didn’t work correctly. In fact, when I echo the $cat_id to see if it called the category, the value came back as ‘array’ rather than an id.

    OOPS! My mistake! Please try this:

    <?php
    $cat = get_the_category();
    $cat_id = $cat[0]->cat_ID;
    query_posts( 'post_type=results' . "&cat=$cat_id"); ?>
    Thread Starter mmulwa

    (@mmulwa)

    AH, that was it! Thanks so much for your quick help. I searched all over google for hours last night. Ya saved me a lot of trouble.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Running a Loop using the same category as a post’ is closed to new replies.