Support » Plugin: Pods - Custom Content Types and Fields » Auto Template display in search

  • Resolved dupontb

    (@dupontb)


    Hello,

    Pods is so great but there is one last thing I don’t find out how to do.

    With Auto Template Option, I display pods content in the_content. It’s working perfectly for single and archive posts but how can I achieve the same result for search results ?

    I could edit search php page but I’d like to use an easy solution like Auto Template.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • dupontb

    (@dupontb)

    I found a way but I don’t like it because. I have to manually code the mapping between a pod type and the template I want to display. I already have done this in the Auto Template Options configuration.

    function the_content_for_type( $content ) {
    	return pods('dog', get_the_id())->template('dog');
    }
    
    add_filter( 'the_content', 'the_content_for_type');
    
    Plugin Author Jim True

    (@jimtrue)

    And that mapping between post-type to Pods Template is exactly why we can’t do it automatically in Search and why we also can’t do that with Taxonomy Archives. Pods Templates aren’t ‘advanced’ enough to be specifically defined by post-type so we do not support doing the ‘auto mapping’ that is necessary to do this in Search or Taxonomy Archives.

    This solution is not supported in any other way than through PHP, sorry.

    dupontb

    (@dupontb)

    Thanks for your reply.

    I managed to do something a little bit more generic based on pod and template name.
    So I have to name my template podName-archive and the template is applied in search too.

    function force_pods_the_content_archive( $content ) {
    	if (is_search() && is_pod()) {
    		return pods(get_post_type(), get_the_id())->template(get_post_type() . '-archive');
    	}
    	return $content;
    }
    add_filter( 'the_content', 'force_pods_the_content_archive');
    Plugin Author Jim True

    (@jimtrue)

    There ya go, nice work 😉

    Plugin Author Jim True

    (@jimtrue)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto Template display in search’ is closed to new replies.