custom fields and custom post type conditional
-
Hello fellow people.
I am gonna start right away:
Setup explanation:
I have 2 portfolio categories (using Avada theme) and I have two different sets of custom fields for each category. I have managed to properly show the correct set of field for the two different categories thus far.<?php $fields = get_field_objects(); if ( $fields ) { ?> <table class="cf-table" width="auto"> <thead><th style="float: left;">HEADING 1</th></thead> <tbody> <?php foreach ( $fields as $field_name => $field ) { if ($field['type'] == 'true_false') { ?> <tr> <td> <?php echo $field['label']; ?></td><td>✓ </td> </tr> <?php } } ?> </tbody> </table> <?php } ?>
Problem
What i want to do now is to show a different < thead > based upon the category the post belongs in. I know that this would normally be achieved by using something like:`<?php
$fields = get_field_objects();if ( $fields ) { ?>
<table class=”cf-table” width=”auto”>
<?php if (is_category(4)) { ?>
<thead><th style=”float: left;”>HEADING 1</th></thead>
<?php } else { ?>
<thead><th style=”float: left;”>HEADING 2</th></thead>
<tbody>
<?php } ?><?php foreach ( $fields as $field_name => $field ) {
if ($field[‘type’] == ‘true_false’) { ?>
<tr>
<td>
<?php echo $field[‘label’]; ?></td><td>✓
</td>
</tr>
<?php }
} ?></tbody>
</table><?php } ?>
Question
So my questions are:
1) Since is_category is not used for custom posts like avada portfolio, which is the correct equivalent ?2) Is this syntax correct?
All tips are appreciated! ??
Thank you
- The topic ‘custom fields and custom post type conditional’ is closed to new replies.