About this topic

  • Posted by DavidS 1 year ago. There are 7 posts. The latest reply is from byron.
  • This topic is not resolved
  1. Does anyone know how to query the database and display an image's custom field in the attachment page?

  2. David,

    At this time, I don't think it's possible. It would take a change to the PhotoSmash core to allow for referencing an image by the Attachment ID...then you could use something like:

    <?php echo do_shortcode("[psmash select_image='current_attachment_id' layout='my_layout']"); ?>

    You could build all of your custom fields into the custom layout 'my_layout' and then display them that way. Unfortunately, the part that doesn't exist is the select_image='current_attachment_id'.

    If you decide to build the code for that, let me know and I'll see about incorporating into the core.
    Cheers,
    Byron

  3. David,

    Actually, you could do it outside of PhotoSmash just using regular old PHP...here's the code:

    <?php

    $imageinfo = $wpdb->get_row("SELECT wp_bwbps_customdata.*, wp_bwbps_images.* FROM wp_bwbps_images LEFT OUTER JOIN wp_bwbps_customdata ON wp_bwbps_customdata.image_id = wp_bwbps_images.image_id WHERE wp_bwbps_images.wp_attach_id = " . (int)$post->ID);

    if( $imageinfo ){
    echo $imageinfo->my_custom_field;
    }

    ?>

    See if that works...

    Cheer,s
    Byron

  4. That's great, Byron! Exactly what I was asking about, the regular old php way of doing it.

    A note to anyone following along: my database tables have a prefix so they go like this: "wp_myprefix_bwbps_customdata" and also replace my_custom_field with the name of your custom field.

    Thanks again.

  5. Welcome!...and you're exactly right... you should replace wp_ with whatever you're using for your database prefix in your wp-config.php.

    Cheers,
    Byron

  6. Hi,

    Where exactly do I post this code:

    <?php

    $imageinfo = $wpdb->get_row("SELECT wp_bwbps_customdata.*, wp_bwbps_images.* FROM wp_bwbps_images LEFT OUTER JOIN wp_bwbps_customdata ON wp_bwbps_customdata.image_id = wp_bwbps_images.image_id WHERE wp_bwbps_images.wp_attach_id = " . (int)$post->ID);

    if( $imageinfo ){
    echo $imageinfo->my_custom_field;
    }

    ?>

    Thanks!
    Mar

  7. You could put it in your attachment.php file in your theme.

    You basically have to put it where ever you want to show a given custom field.

    Cheers,
    Byron

RSS feed for this topic