0

I need to define the Category ID in my singles page through custom fields so that i can load a different category depending on the page. This is what i have so far and its not working.

Any help would be greatly appreciated thanks.

 <?php query_posts( 'cat=<?php echo get_post_meta($post->ID, 'BarID', true); ?>id&showposts=1000' ); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <!-- BEER ITEM -->
            <div class="menu-title">
            <span><?php the_title(); ?></span>
            </div>
            <div class="menu-desc-wrap">
            <div class="beer-discripton">
            <span></span>
            <?php the_content(); ?>
            </div>
            <div class="percent"><span> <?php echo get_post_meta($post->ID, 'Percent', true); ?></span></div>
            </div>
            <!-- BEER ITEM END -->
<?php endwhile; ?>

<?php else : ?>

<p>Not Found</p>

<?php endif; ?>

Ive also tried this:

<?php $cataID = get_post_meta($post->ID, 'cata', false); ?>

        <div class="one-half column">
        <h3 class="title-color"><img class="img-valign-draft" src="<?php bloginfo('template_directory'); ?>/images/draft-bottle/draft.svg" alt="">Draft</h3>

           <?php query_posts( 'cat='$cata'&showposts=1000' ); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <!-- BEER ITEM -->
            <div class="menu-title">
            <span><?php the_title(); ?></span>
            </div>
            <div class="menu-desc-wrap">
            <div class="beer-discripton">
            <span></span>
            <?php the_content(); ?>
            </div>
            <div class="percent"><span> <?php echo get_post_meta($post->ID, 'Percent', true); ?></span></div>
            </div>
            <!-- BEER ITEM END -->
<?php endwhile; ?>

<?php else : ?>

<p>Not Found</p>

<?php endif; ?>
  • Are you storing cateroy in a meta field? Why if the category is already assigned and can be get using, for example, get_the_category()? – cybmeta Apr 9 '15 at 10:09
  • I need to be able to set the category from a wordpress post, as i am only using the one single.php – Chris Rodgers Apr 9 '15 at 10:19
  • 2
    I'm sorry but I don't understand you. You can set the category when you edit/create a post. Then you can get the category that the post belongs to through several mehtods, like get_the_category() function, meta fields are not involved. I don't understnd what you are trying to do. – cybmeta Apr 9 '15 at 10:28
0
<?php 
global $wp_query;
 $cata = get_post_meta( get_the_ID(), 'cata', false);  
query_posts (
array(
    'cat'=> $cata,
    'showposts' =>'1000'
    )
);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  <!-- BEER ITEM -->
        <div class="menu-title">
        <span><?php the_title(); ?></span>
        </div>
        <div class="menu-desc-wrap">
        <div class="beer-discripton">
        <span></span>
        <?php the_content(); ?>
        </div>
        <div class="percent"><span> <?php echo get_post_meta( get_the_ID(), 'Percent', true ); ?></span></div>
        </div>
        <!-- BEER ITEM END -->
<?php endwhile; endif; wp_reset_query(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.