• Resolved joewnc

    (@joewnc)


    Hello,

    Do you know of anyone who has customized the plugin to index attachments as built, but use the postmeta table to return the post/page associated with the featured image rather than a link to the image in the wp-content folder/url?

    The use case is I run several newspapers, and the “caption” field when uploading media is where the journalists put the photographer credit. We need to be able to index the photographer bylines, but ideally would want to return the story/commentary where their image was used, not the image itself.

    Going to get into trying to build this custom tomorrow, but figured it might be worth asking if you had seen someone do it before or if you had any advice on the method.

    Thanks for your input, and for all of the incredible feedback you’ve provided during the lifetime of this plugin!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yes, Relevanssi Premium does something like this, as you can index the attachment content either for the attachment itself, or for the parent post.

    The trick is to add an indexing filter that will find all the attachments for a post, fetch the desired data out of it and index that for the parent post. The image caption is stored in the post excerpt, so you’d basically find all the post excerpts for the attached posts for each post.

    Something like this should do the trick:

    add_filter( 'relevanssi_content_to_index', 'rlv_add_attachment_excerpts', 10, 2 );
    function rlv_add_attachment_excerpts( $content, $post ) {
        global $wpdb;
        $results = $wpdb->get_col( $wpdb->prepare( "SELECT post_excerpt FROM $wpdb->posts WHERE post_parent = %d", $post->ID ) );
        foreach ( $results as $excerpt ) {
            $content .= " $excerpt";
        }
        return $content;
    }

    Now just index the posts, but don’t index the attachments, and the attachment captions will be indexed for the parent post.

    Thread Starter joewnc

    (@joewnc)

    This worked perfectly, and is such a more straightforward and direct way to do it then what I had planned to try to muster up. Thank you so much for your help, and for the incredible support.

    Plugin Author Mikko Saari

    (@msaari)

    Thanks for the review, that helps a lot!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Return Page of Attachment, Not Attachment’ is closed to new replies.