Skip to main contentSkip to footer

Gmedia photo gallery gives a false impression of working with Relevanssi, as you can see the gmedia_tag taxonomy appear in the list of taxonomies:

Gmedia tags
gmedia_tag is listed in the list of taxonomies to index.

However, if you try to index those tags, you’ll soon notice Relevanssi isn’t actually indexing them. That’s because Gmedia gallery doesn’t use that taxonomy for the tags. The tags are actually in a separate, proprietary taxonomy Relevanssi won’t have access at all.

There is a solution, though. When indexing gallery photos, you can add a function that reads in the actual Gmedia tags, and adds them to the post content before it is indexed by Relevanssi. The code looks something like this:

add_filter( 'relevanssi_content_to_index', 'rlv_index_gmedia_tags', 10, 2 );
function rlv_index_gmedia_tags( $content, $post ) {
	if ( 'gmedia' === $post->post_type ) {
		$id = get_post_meta( $post->ID, '_gmedia_ID', true );
		if ( ! empty( $id ) ) {
			global $gmDB;
			$tags = $gmDB->get_the_gmedia_terms( $id, 'gmedia_tag' );
			if ( is_array( $tags ) ) {
				foreach ( $tags as $tag ) {
					$content .= $tag->name;
				}
			}
		}
	}
	return $content;
}

This checks the post type: if it’s gmedia, the photo ID in the Gmedia database is fetched from the _gmedia_ID custom field. That ID is then used to fetch the terms with $gmDB->get_the_gmedia_terms( $id, 'gmedia_tag' );. The terms are then looped through and the term name is added to the post content, where it will be indexed.

There’s lots of subtle finesses that are missing – this code will for example make your site crash if Gmedia is disabled at some point, but it should get you started with adding better support for Gmedia photo galleries.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Yoast Local SEO
Yoast Local SEO plugin breaks Relevanssi search. It enhances the search by adding meta queries. Unfortunately they don’t work with…
Excluding protected posts

A site I’m working with has a handful of “protected” posts (password required to view). For various reasons, we don’t want to show these in search results. While there is no excerpt shown, I’d prefer for people to not even know they exist. Relevanssi sees protected posts as public posts……(because their post status is publish, not private like with private posts). That’s what they are, as, in general, users will be able to see protected posts. Just not their content unless they know the password. Relevanssi does protect the content and won’t show parts of it in excerpts. If……you want to deindex protected posts completely, add this code to your site: add_filter( ‘relevanssi_indexing_restriction’, ‘rlv_exclude_protected’ ); function rlv_exclude_protected( $restriction ) { global $wpdb; $restriction[‘mysql’] .= ” AND post.post_password = ””; $restriction[‘reason’] .= ‘ Has a password’; return $restriction; } Then just rebuild the index. This will prevent Relevanssi from…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed