For a post object field is it possible to check the post type of the field value?
Eg:
post_object_field – restricted to two post types A and B
We want to output a link to the post if it’s post type A but output only the name if it’s post type B.
I’ve tried using is_singular(‘horses’) but that’s not working so guessing that’s not how we’d need to check the post type?
This is the full code:
<?php
$dam = get_field('dam');
if( $dam ):
$post = $dam;
setup_postdata( $post );
?>
<?php if ( is_singular('horses') ) :?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php else:?>
<?php the_title(); ?>
<?php endif;?>
<?php wp_reset_postdata();?>
<?php endif; ?>
Nevermind, figured it!
For anyone else with the same question we needed to use: get_post_type( get_the_ID() ) and set it as a variable.
Eg:
<?php
$post_type = get_post_type( get_the_ID() );
if ( $post_type == 'horses'):?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
<?php else:?>
<?php the_title(); ?>
<?php endif;?>