Skip Navigation

[Resolved] Modify text shown in Custom Search Results archive for specific post type

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show "Filed under: News" instead of "Filed under: Posts" on my custom search results archive page.

Solution: Use a conditional statement to test the post type of the current post in the loop, and display different text depending on the results of that test.

Filed under: [wpv-conditional if="( '[wpv-post-type]' eq 'post' )"]News[/wpv-conditional]

Relevant Documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by winyS 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#585179
Schermafbeelding 2017-11-02 om 10.16.16.png

I created a custom archive for search results.

To make it work with Relevanssi I followed this topic: https://toolset.com/forums/topic/custom-search-relevanssi/.
I added some code to functions.php of my theme. This makes highlight search term work.

You can view the result I have so far here: hidden link

First question: The excerpt in the search results is wrapped in <p></p> tags. However, I did not add these to my template in the Views WordPress archive. (view screenshot)
How can I get rid of these tags?

A second question is that I would like to show the Post type in the search results:
Filed under: Posts
Instead of "Posts" (the content type name) I would like to display: "News". How can I do that?

#585580

First question: The excerpt in the search results is wrapped in <p></p> tags. However, I did not add these to my template in the Views WordPress archive. (view screenshot) How can I get rid of these tags?
Hi, as a test, can you please temporarily remove the highlight_keyword shortcode? Is the extra p tag still included?

Instead of "Posts" (the content type name) I would like to display: "News". How can I do that?
You can use conditional HTML here. If the post type is equal to "post", then display "News" instead.

Filed under: [wpv-conditional if="( '[wpv-post-type]' eq 'post' )"]News[/wpv-conditional]

More information about conditional HTML:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#585881

Thank you, Christian,

The conditional HTML works fine. This part is resolved.

Not yet resolved:
I temporarily removed the highlight_keyword shortcode. Then extra p tag disappeared?
How can I resolve this?

#586456

I'm not familiar with the highlight_keyword shortcode. It's not native to WordPress, so it must be coming from somewhere else, like a theme or 3rd-party plugin. Can you tell me more about how it's implemented?

#587117

Hello Cristian,

The highlight_keyword shortcode is not native to WordPress. Here is how I implemented it:
I followed this tutorial. https://toolset.com/forums/topic/custom-search-relevanssi/.
I added the following to my functions.php:

// highlight keyword with relevanssi
// https://toolset.com/forums/topic/custom-search-relevanssi/
function highlight_keyword_func($atts, $content) {
    $content = do_shortcode($content);
    if(isset($_GET['s'])){
        $content = relevanssi_highlight_terms($content, $_GET['s']);
    }
    return $content;
}
add_shortcode( 'highlight-keyword', 'highlight_keyword_func' );

This is how I implemented the shortcode in the Toolset Views WordPress template:

[wpv-layout-start]
    [wpv-items-found]
<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<li>
			<h3>[wpv-post-link]</h3>
          	<p><em>[wpv-post-date]<br>Filed under: [wpv-conditional if="( '[wpv-post-type]' eq 'post' )"]News[/wpv-conditional][wpv-conditional if="( '[wpv-post-type]' ne 'post' )"][wpv-post-type show="plural"][/wpv-conditional] [wpv-conditional if="( '[wpv-post-type]' eq 'post' )"] - [wpv-post-taxonomy type="category" format="name"][/wpv-conditional]</em>
             <br />
            [highlight-keyword][wpv-post-excerpt][/highlight-keyword]
           	</p>
			</li>
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-layout-end]
#587189

Okay there's an option for the wpv-post-excerpt shortcode that might help suppress these paragraph tags. Try this:

 [highlight-keyword][wpv-post-excerpt format="noautop"][/highlight-keyword]
#587265

Thank you Christian, this works!