Reputation: 1322
So I am using Advanced Custom Fields for Wordpress, and I have a repeater sub_field where you either can link a file for download, or choose a page link in a different field for an tag my page. My two fields are named: fil_url page_url
This is my normal markup, which returns one, in this case the uploaded file. php/html:
<a href="<?php the_sub_field('fil_url')):) ?>open</a>
So what I want is an if-statement that says that if fil_url is empty, then display page_url instead. But I'm not sure how to write this. Plz help :)
Upvotes: 0
Views: 349
Reputation: 1322
After tinkering with @diggy's post I found this sollution:
<?php
$href = ( get_sub_field( 'fil_url' ) ) ? get_sub_field( 'fil_url' ) : get_sub_field( 'page_url' );
<?>
Upvotes: 0
Reputation: 6838
<?php
$file_url = get_sub_field( 'fil_url' );
$href = ( ! empty( $file_url ) ) ? get_sub_field( 'fil_url' ) : get_sub_field( 'page_url' );
echo '<a href="' . $href . '">open</a>';
?>
Upvotes: 1