Reputation: 1762
I have an advanced custom field group, and inside the group and inside the group are a few fields and one select field in where the user selects a category. I want to output onto the page based on what category has been chosen.
Here is the code I was trying:
<?php
$limit = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('post_type=Specialist_post&showposts=' . $limit . '&paged=' . $paged);
$wp_query->is_archive = true; $wp_query->is_home = false;
if(have_posts()) :
while(have_posts()) :
the_post();
if(get_field('category') == "1402")
{ ?>
<div class="row wheelsspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php } else if (get_field('category') == "1403") {?>
<div class="row tuningspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php } ?>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
This now outputs nothing, if i echo the field category its returning 1403, so i would think it at least outputs the else if, maybe this whole code design is wrong. Essentially i want to print different into different divs based on the category selected.
Upvotes: 0
Views: 482
Reputation: 1762
Did it this way, not the ideal solution, works for now, just needs a code review
<div class="row wheelsspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'Specialist_post',
'meta_key' => 'category',
'meta_value' => '1402'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
<div class="row tuningspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'Specialist_post',
'meta_key' => 'category',
'meta_value' => '1403'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
Thanks all
Upvotes: 0