[Resolved] Need a little help with custom fields on attachment page

Home Forums Support [Resolved] Need a little help with custom fields on attachment page

Home Forums Support Need a little help with custom fields on attachment page

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1090678
    Alexander

    Hello,

    I created a Hook element to show additional information about prints and licensing of my photos on their attachment page. I also created a custom field that contains a link to an external site where a print can be purchased. Aaaaand (I’m quite proud of myself here;-) I managed to put these things together so that it does what I want – at least for those attachments which HAVE the custom field set… and not all of them do. :-/

    Here’s my code in the Hook:

    <p>
    <?php
    	global $post;
    	$faa_url = get_post_meta( $post->ID, 'store_link', true );
    	printf( '<br>PRINTS: <a href=" %s " TARGET="_BLANK">purchase an open edition fine art print</a> of this photo, directly in my print-on-demand store.', $faa_url );
    ?>
    </p>
    <p>
    	LICENSING: To inquire about licensing this photo, please <a href="/contact/">contact me.</a>
    </p>

    Here’s an example where it looks like it should, where the custom field ‘store_link’ is set: https://www.alex-kunz.com/portfolio/black-white-portfolio-gallery/soul-sleeping/

    But here’s an example where the custom field ‘store_link’ is NOT set: https://www.alex-kunz.com/portfolio/black-white-portfolio-gallery/hill-1948/

    To resolve this, I’d like to make the output of my code conditional: if the custom field ‘store_link’ is not present or empty, output “text A”. If it’s set, output “text B”.

    My problem is that when the custom field is not set, the variable $faa_url contains the attachment URL itself?! Or at least it seems that way to me…

    I hope this isn’t too generic and/or trivial. Thanks!

    #1090717
    Alexander

    Oh man… that WAS trivial… an IF – ELSE clause was all that I needed, of course (and the help of a PHP Syntax checker;-).

    #1090718
    Leo
    Staff
    Customer Support

    Glad you’ve figured out 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.