• Resolved regnalf

    (@regnalf)


    I would like to use Relevanssi on one of my pages because it also searches shortcodes.

    The theme pro (from ThemeCo) which I mainly use generates more dynamic content using custom shortcodes like {{dc:post:title}}, which displays the title of the post.

    Would it be possible to search the complete parsed content?

    Also, the search behaves strangely when you are logged in or not. It even redirects to the home page instead of showing “No search term found”.

Viewing 15 replies - 31 through 45 (of 47 total)
  • Thread Starter regnalf

    (@regnalf)

    Eureka, I got it to work now.

    The hook is called, there was an error in my error log that went to the wrong file. Sorry for about that!

    Also, I have now found the correct function for processing the content filter. pro theme needs the post object to correctly process its custom routines.

    Here is the correct code, maybe helpfull for others.

    add_filter( 'relevanssi_post_content', 'relevanssi_filter_the_content', 10, 2 );
    function relevanssi_filter_the_content( $post_content, $post )
    {
    	return apply_filters( 'the_content', $post->post_content );
    }

    But i still got the wrong content in the search results exception. Is there a hook to filter this output with the object?

    And many many thanks for the support and patience!!!

    Plugin Author Mikko Saari

    (@msaari)

    You can use the same function on the relevanssi_excerpt_content filter hook, it takes the same parameters and works the same. If that doesn’t work for some reason, try relevanssi_pre_excerpt_content – the difference between these two is that the pre version runs before Relevanssi runs the_content and the other one happens after.

    Thread Starter regnalf

    (@regnalf)

    Yes, relevanssi_pre_excerpt_content does at it should be.

    Maybe you could add this to your documentation that some themes, like pro from theme.co, needs the post object instead of the content string.

    Thanks again for the patience.

    *****

    Plugin Author Mikko Saari

    (@msaari)

    Can you maybe compare what’s the actual difference between $post_content and $post->post_content there? Because $post_content in the relevanssi_post_content filter hook is $post->post_content, the two should be exactly the same thing, with zero difference between them.

    Thread Starter regnalf

    (@regnalf)

    This is not quite understandable for me either, I have quoted the support response from Theme.co below.

    It’s just that if I use the passed string with the content, the content is not revised correctly. If I do it with the post object it works fine.

    The Dynamic Content tags are not being parsed like the shortcode and added to the Content of the WordPress. You are using the 3rd Party plugin that might use the Content only to search.

    The the_content function only works with WP_Query object where get_post function returns the POST object where you need to use the post_content porperty like $post->post_content. If you need that to be filtered with the the_content, you can use the following code.

    $output = apply_filters( 'the_content', $post->post_content );

    Plugin Author Mikko Saari

    (@msaari)

    The thing is, you’re not passing the post object – you’re passing just the content string, and the string should be exactly the same as the $post_content, because that too is taken just as directly from the post object.

    But if it requires to be inside a Loop, I can understand that – but whether you pass the filter $post_content or $post->post_content shouldn’t make any difference to that… But I guess I’ll just chalk this up as one of the mysteries of nonstandard theme development. =D

    Thread Starter regnalf

    (@regnalf)

    In WordPress there happens many unsolved mysteries, i wondering every day 😉

    Plugin Author Mikko Saari

    (@msaari)

    Anyway, I posted this to my knowledge base, hopefully next time this comes up it’ll be easier. Thanks for the review!

    Thread Starter regnalf

    (@regnalf)

    Just for the record, here are the two results from the different calls from “the_content” in same function!:

    apply_filters( 'the_content', $post_content )

    <p> Preise<br />
    {{dc:term:name term=”6″}}, {{dc:term:name term=”5″}}:<br />
    1. Rang € 18,-2. Rang € 15,-Kinder unter 15 Jahren € 8,-<br />
    {{dc:term:name term=”7″}}<br />
    Kinder € 8,-Erwachsene € 13,-\n\n Theaterabo<br />
    Ihre Geschenkidee!Schenken Sie ein Theaterabo der Bühne um € 42,–<br />
    Das Abo beinhaltet:1 Karte {{dc:term:name term=”5″}} (1. Rang)1 Karte {{dc:term:name term=”6″}} (1. Rang)1 Karte {{dc:term:name term=”7″}} (Erwachsener)<br />
    Sie sparen 14%.<br />
    Sie erhalten das Abo bei BP.\n\n </p>

    apply_filters( 'the_content', $post->post_content )

    <div id=”cs-content” class=”cs-content” >
    <div class=”e896-1 x-section”>

    <div class=”e896-2 x-row x-container max width”>
    <div class=”x-row-inner”>
    <div class=”e896-3 x-col”>

    <div class=”e896-4 x-text”>
    <h3>Preise</h3>
    <p>Theatersommer, Lenziade:</p>
    <p>1. Rang € 18,-<br />2. Rang € 15,-<br />Kinder unter 15 Jahren € 8,-</p>
    <p>Weihnachtsstück</p>
    <p>Kinder € 8,-<br />Erwachsene € 13,-</p></div>
    </div>

    <div class=”e896-5 x-col”>

    <div class=”e896-6 x-text”>
    <h3>Theaterabo</h3>
    <p>Ihre Geschenkidee!<br />Schenken Sie ein Theaterabo der Bühne um € 42,–</p>
    <p>Das Abo beinhaltet:<br />1 Karte Lenziade (1. Rang)<br />1 Karte Theatersommer (1. Rang)<br />1 Karte Weihnachtsstück (Erwachsener)</p>
    <p>Sie sparen 14%.</p>
    <p>Sie erhalten das Abo bei BP.</p></div>
    </div>
    </div>
    </div>
    </div>
    </div>

    Plugin Author Mikko Saari

    (@msaari)

    Are the source strings identical, or is there a difference between them?

    Thread Starter regnalf

    (@regnalf)

    There seems to be a difference:

    My error log functions that i use for this put out this content for the $post_content string:

    bhstein_error_log ("post_content: " . $post_content);

    post_content: Preise
    {{dc:term:name term=”6″}}, {{dc:term:name term=”5″}}:
    1. Rang € 18,-2. Rang € 15,-Kinder unter 15 Jahren € 8,-
    {{dc:term:name term=”7″}}
    Kinder € 8,-Erwachsene € 13,-\n\n Theaterabo
    Ihre Geschenkidee!Schenken Sie ein Theaterabo der Bühne um € 42,–
    Das Abo beinhaltet:1 Karte {{dc:term:name term=”5″}} (1. Rang)1 Karte {{dc:term:name term=”6″}} (1. Rang)1 Karte {{dc:term:name term=”7″}} (Erwachsener)
    Sie sparen 14%.
    Sie erhalten das Abo bei BP.\n\n

    bhstein_error_log ("post->the_content: (" . $post->the_content . ")");

    post->the_content: ()

    It put out nothing. As i said, i wondering too!

    Plugin Author Mikko Saari

    (@msaari)

    $post->the_content doesn’t exist, it should be $post->post_content.

    Thread Starter regnalf

    (@regnalf)

    Sorry, that was my failure now, i was to confused with the_content

    Here is the correct output from $post->post_content:

    bhstein_error_log ("post->post_content" . $post->post_content);

    post->post_content: [cs_content][cs_element_section _id=”1″ ][cs_element_layout_row _id=”2″ ][cs_element_layout_column _id=”3″ ][cs_element_text _id=”4″ ][cs_content_seo]Preise
    {{dc:term:name term=”6″}}, {{dc:term:name term=”5″}}:
    1. Rang € 18,-2. Rang € 15,-Kinder unter 15 Jahren € 8,-
    {{dc:term:name term=”7″}}
    Kinder € 8,-Erwachsene € 13,-\n\n[/cs_content_seo][/cs_element_layout_column][cs_element_layout_column _id=”5″ ][cs_element_text _id=”6″ ][cs_content_seo]Theaterabo
    Ihre Geschenkidee!Schenken Sie ein Theaterabo der Bühne um € 42,–
    Das Abo beinhaltet:1 Karte {{dc:term:name term=”5″}} (1. Rang)1 Karte {{dc:term:name term=”6″}} (1. Rang)1 Karte {{dc:term:name term=”7″}} (Erwachsener)
    Sie sparen 14%.
    Sie erhalten das Abo bei BP .\n\n[/cs_content_seo][/cs_element_layout_column][/cs_element_layout_row][/cs_element_section][/cs_content]`

    Could it be that the $post_content string is pre filtered?

    Plugin Author Mikko Saari

    (@msaari)

    Ah, yes! That’s the difference. Relevanssi strips page builder shortcodes in the same filter hook on an earlier priority, that’s why all those [cs_...] shortcodes are removed.

    If that’s indeed the case, this might get you good results:

    add_filter( 'relevanssi_post_content', 'relevanssi_filter_the_content', 8, 2 );
    function relevanssi_filter_the_content( $post_content, $post ) {
    	return apply_filters( 'the_content', $post_content );
    }

    The page builder shortcodes are removed on priority 9, so if your filter function runs on an earlier priority, that should do the trick.

    Thread Starter regnalf

    (@regnalf)

    Yupp, that was the issue. It works now with the $post_content string too.
    I added the priority 10 by myself because it is the suggested level from wordpress reference.

    So from the programmers point of view, is it better to use the lower priority with the $post_content string or should i stay with the $post->post_content?
    Maybe you change your priority in the future to, let’s say 7 or so and it won’t work again? Or did i oversee something else in the chain of process?

Viewing 15 replies - 31 through 45 (of 47 total)
  • The topic ‘Dynamic Content with theme pro’ is closed to new replies.