Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter nlstmmic

    (@nlstmmic)

    Thanks I think your suggestion worked.

    Thread Starter nlstmmic

    (@nlstmmic)

    I’ve been dedicated to this, simply because I’ve run into this issue in the past, dealing with WordPress without Relevanssi, and exhausted 100s of hours researching trying to figure it out. And I still don’t know quite how to do it without Relevanssi, but here are the solutions.

    To use 2 different functions in 2 different custom templates using 2 different page id’s

    you got to set the

    $content .= '' . "Some Content";

    i.e

    Function 1 custom template content-home.php with post id 120

    function testing_function_1( $content, $post ) {
        if ( 120 === $post->ID ) {
            $content .= '' . "Testing Something Crucial on my site";
        }
        return $content;
    }
    add_filter( 'relevanssi_content_to_index', 'testing_function_1', 10, 2 );
    add_filter( 'relevanssi_excerpt_content', 'testing_function_1', 10, 2 );

    Function 2 custom template content-about.php with post id 130

    function testing_function_2( $content, $post ) {
        if ( 130 === $post->ID ) {
            $content .= '' . "Testing Something Crucial on my site";
        }
        return $content;
    }
    add_filter( 'relevanssi_content_to_index', 'testing_function_2', 10, 2 );
    add_filter( 'relevanssi_excerpt_content', 'testing_function_2', 10, 2 );

    And all this is according to your doc here https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_content_to_index/

    But I just overlooked that note.

    I also added,

    global $content;

    in the custom content-home.php and other templates that I want to use.

    In the Plugin Relevanssi, in WordPress itself settings

    In the Searching Tab, I use

    AND - Require all Terms

    Disable the OR fallback.

    Whole Words

    Now Dealing with ACF, and building a function to echo out in a custom template for example

    This is how I modified the ACF function, from earlier in this discussion and it works great too now with the relevanssi_content_to_index and relevanssi_excerpt_content

    function eleven_area_agencies_on_aging($content, $post){
    
                if (get_post_meta( 6210, 'show11areaagenciesonaging', true )) {
    				
    				
    				
    				$content_url = content_url();
    
                    $content11areaagenciesonaging = get_post_meta( 6210, 'content11areaagenciesonaging', true );
    
                    $output = '';
    				
    				$i = '';
    
                    foreach (range(1, get_post_meta( 6210, 'psacount' . $i, true )) as $i) {
    
                        $a = get_post_meta( 6210, 'psaphone' . $i, true );
    
                        $phone = str_replace("(", "", str_replace(")", "", str_replace("-", "", str_replace(" ", "", $a))));
    
                        $phone_modified = str_replace('-', '', $phone);
    
                        $psa1colorcode = get_post_meta( 6210, 'psa1colorcode' . $i, true );
    
                        $psa = get_post_meta( 6210, 'psa' . $i, true );
    
                        $psatitle = get_post_meta( 6210, 'psatitle' . $i, true );
    					
                        $psagooglemapaddresslink = get_post_meta( 6210, 'psagooglemapaddresslink' . $i, true );
    
                        $psastreetaddress = get_post_meta( 6210, 'psastreetaddress' . $i, true );
    
                        $psacitystatezip = get_post_meta( 6210, 'psacitystatezip' . $i, true );
    
                        $psaphone = get_post_meta( 6210, 'psaphone' . $i, true );
    
                        $psawebsitelink = get_post_meta( 6210, 'psawebsitelink' . $i, true );
    
                        $output .= "
              
             <div class='col-sm-4'>
             <div class='psa-class'>
                <h3 class='text-align-center white' style='background: $psa1colorcode ;'>$psa </h3>
                <p title='$psatitle' class='text-align-center h55'><strong>$psatitle</strong></p>
                <a href='$psagooglemapaddresslink;' target='open_blank'><img class='lazy map-icon' data-src='$content_url/uploads/google-maps-icon.png' /></a>
                <address class='address text-align-center'>$psastreetaddress <br>$psacitystatezip</address>
                <p class='text-align-center'><a href='tel:$phone_modified' class='phone-icon'>$psaphone</a></p>
                <div class='text-align-center risk-detector'> <a class='external-link' href='$psawebsitelink' target='open_blank' title='Go To: $psawebsitelink'>Website</a> </div>
             </div>
             </div>";
    
                    }
    
                   if (120 === $post->ID || 1152 === $post->ID) {
    
                        $content .= ' ' . "$content11areaagenciesonaging<div id='psa-section' class='bs-container' style='clear: both;'><div class='row'>$output</div></div>";
    			   
    			   }
                  
    
                    return "$content";
    				
    				 
    
                }else{
    				
    				
    				
    
                    if (!empty(get_post_meta( 6210, 'psacotentalternative', true ))){
    
    				               
    			
    					$content .=  ' ' . get_post_meta( 6210, 'psacotentalternative', true );
    					
    					return "$content";
    					
    				
    
                    }
    
                }
            
           
        
    }

    Using

    get_post_meta( 6210, 'acf_field', true );

    Also is required as mentioned earlier in the discussion, so using the_field() or get_field() will not work where Relevanssi is concerned.

    What else I learned is if in ACF using get_post_meta( 6210, 'acf_field', true ); happens to be WSYIWYG field, it will strip out the <p> tags, and I think Relevanssi index gets hung up there too.

    So you also need to add these to your functions.php file

    add_filter( 'meta_content', 'wptexturize' );
    add_filter( 'meta_content', 'convert_smilies' );
    add_filter( 'meta_content', 'convert_chars' );
    add_filter( 'meta_content', 'wpautop' );
    add_filter( 'meta_content', 'shortcode_unautop' );
    add_filter( 'meta_content', 'prepend_attachment' );

    and then use

    apply_filters('meta_content', get_post_meta( 6210, 'acf_field', true ));

    In order to retrieve A WYSIWYG ACF Field.

    • This reply was modified 3 years, 6 months ago by nlstmmic.
    Thread Starter nlstmmic

    (@nlstmmic)

    I have been at this for days really trying to get this to work well.

    This is a scenario I have

    Both of these functions below go to page id 120 which is the home page

    sub_domain_image_section();
    
    add_filter('relevanssi_content_to_index', 'sub_domain_image_section', 10, 2);
    add_filter('relevanssi_excerpt_content', 'sub_domain_image_section', 10, 2);
    
    eleven_area_agencies_on_aging();
    
    add_filter('relevanssi_content_to_index', 'eleven_area_agencies_on_aging', 10, 2);
    add_filter('relevanssi_excerpt_content', 'eleven_area_agencies_on_aging', 10, 2);

    This function below goes to a different page id 7115

    frequently_asked_questions_specific_to_web_portal();
    
    add_filter('relevanssi_content_to_index', 'frequently_asked_questions_specific_to_web_portal', 10, 2);
    add_filter('relevanssi_excerpt_content', 'frequently_asked_questions_specific_to_web_portal', 10, 2);

    This Function below goes to page ID 7049

    faq_exemption_from_disqualification_process();
    
    add_filter('relevanssi_content_to_index', 'faq_exemption_from_disqualification_process', 10, 2);
    add_filter('relevanssi_excerpt_content', 'faq_exemption_from_disqualification_process', 10, 2);

    So I load all the filters in the functions.php file. For example if I am targeting page id 120 the home page using 2 separate functions it will work, but when I add filters to the other pages functions it only grabs the last filter loaded in the functions.php file. I tried messing around with the priorities, but same thing again.

    Thread Starter nlstmmic

    (@nlstmmic)

    Nevermind, I got it working again with ACF the way I want, but you have to use get_post_meta( 6210, ‘field’, true ); instead of get_field() which also according to your doc here –> https://www.relevanssi.com/knowledge-base/indexing-acf-relationship-content/

    Thread Starter nlstmmic

    (@nlstmmic)

    Hi Im back so Ive run into the same issue again.

    In the earlier messages I was giving you a basic Example of a hard coded function that I wanted to essentially get indexed. And those examples above worked.

    In reality I am actually dealing with ACF. But I understand that Relevanssi can do this easily right, and that’s not the issue Im running into in a way. for example I have a custom post_type slug called home_page_settings and Relevanssi will index the custom post_type URL with the slug home_page_setting, however that is simply not what I want to have happen. You see I am outputting ACF on the home page custom template.php file, so when a user searches for content we know is on the home page being output by ACF then the results should indicate that that content is located on the home page.

    So in reality the hardcoded function I have in my custom template is this

    function eleven_area_agencies_on_aging($content, $post){
    
     
        if (120 === $post->ID) {
    
        $content_url = content_url();
    
        $args = array(
            'post_type' => 'home_page_settings',
            'post_status' => 'publish',
            'p' => 6210
        );
    
        $home_page_settings = new WP_Query($args);
    
        if ($home_page_settings->have_posts())
        {
    
            while ($home_page_settings->have_posts())
            {
    
                $home_page_settings->the_post();
    
                if (get_field('show11areaagenciesonaging'))
                {
    
                    $content11areaagenciesonaging = get_field('content11areaagenciesonaging');
    
                    $output = '';
    
                    foreach (range(1, get_field('psacount')) as $i)
                    {
    
                        $a = get_field('psaphone' . $i);
    
                        $phone = str_replace("(", "", str_replace(")", "", str_replace("-", "", str_replace(" ", "", $a))));
    
                        $phone_modified = str_replace('-', '', $phone);
    
                        $psa1colorcode = get_field('psa1colorcode' . $i);
    
                        $psa = get_field('psa' . $i);
    
                        $psatitle = get_field('psatitle' . $i);
    
                        $psagooglemapaddresslink = get_field('psagooglemapaddresslink' . $i);
    
                        $psastreetaddress = get_field('psastreetaddress' . $i);
    
                        $psacitystatezip = get_field('psacitystatezip' . $i);
    
                        $psaphone = get_field('psaphone' . $i);
    
                        $psawebsitelink = get_field('psawebsitelink' . $i);
    
                        $output .= "
              
             <div class='col-sm-4'>
             <div class='psa-class'>
                <h3 class='text-align-center white' style='background: $psa1colorcode ;'>$psa </h3>
                <p title='$psatitle' class='text-align-center h55'><strong>$psatitle</strong></p>
                <a href='$psagooglemapaddresslink;' target='open_blank'><img class='lazy map-icon' data-src='$content_url/uploads/google-maps-icon.png' /></a>
                <address class='address text-align-center'>$psastreetaddress <br>$psacitystatezip</address>
                <p class='text-align-center'><a href='tel:$phone_modified' class='phone-icon'>$psaphone</a></p>
                <div class='text-align-center risk-detector'> <a class='external-link' href='$psawebsitelink' target='open_blank' title='Go To: $psawebsitelink'>Website</a> </div>
             </div>
             </div>";
    
                    }
    
               
    
                        $content .= "$content11areaagenciesonaging<div id='psa-section' class='bs-container' style='clear: both;'><div class='row'>$output</div></div>";
    				
                  
    
                    return (string) $content;
    				
    				 
    
                }
                else
                {
    
                    if (!empty(get_field('psacotentalternative')))
                    {
    
    				                
    			
    					$content .=  get_field('psacotentalternative');
    					
    					return (string) $content;
    					
    				
    
                    }
    
                }
            }
            wp_reset_postdata();
        }
    }
    }
    
    add_filter('relevanssi_content_to_index', 'eleven_area_agencies_on_aging', 10, 2);
    add_filter('relevanssi_excerpt_content', 'eleven_area_agencies_on_aging', 10, 2);

    I applied your recommendations from earlier in the discussion but when building the index again no dice, it just doesn’t pick it up at all now, it will with the other easy function returning a string, but not this function.

    120 is the post id for the home page and 6210 is the id for the home_page_settings custom post type.

    Let me know if you think there is a different idea of achieving this. Im lost, the function works great it outputs what I need it to, but can’t but cannot use your filters with it.

    Thread Starter nlstmmic

    (@nlstmmic)

    This is perfect, you are awesome my friend.

    I also changed out the_excerpt() function in my search.php file and replaced it with

    <?php relevanssi_the_excerpt(); ?>

    and now it displaying the echoed contents of a function and the relevancy of an exact match phrase sets it as the first result.

    This is truly a great plugin. Thank you again kindly for all your help.

    Thread Starter nlstmmic

    (@nlstmmic)

    Ok, everything you mentioned here sort of worked. However getting some relevancy problems.

    Meaning I echoed that function to the custom home page template. I can find it in search results now but its like 59 on the list of a lot of pages I got when I do a search for exact phrase “Testing Something Crucial on my site” or any variation of that. I even have preference made to exact match phrases too.

    But its only showing the title of the Page “Home” which is good but no excerpt.

    is there a filter for relevanssi_excerpt_to_index

    I tried this filter relevanssi_excerpt_content but it appends the testing_function() string output to all the excerpts for every page which is what I don’t want.

    My thought is if I can get the excerpt indexed now, when I do an exact match phrase search it will show up first is the goal.

    In my search.php file I am processing the WordPress the_excerpt()

    Thank you so much for your continued help, so far this is the most progress the internet and WordPress has ever made on this subject.

    Thread Starter nlstmmic

    (@nlstmmic)

    Thank you I started researching this

    relevanssi_content_to_index

    So lets say I have this function

    function testing_function($content){
    	
    	$content .= "Testing Something Crucial on my site";
    	
    	return $content;
    	
    	
    }
    
    add_filter( 'relevanssi_content_to_index', 'testing_function', 10, 2 );

    then I use

    <?PHP echo testing_function() ?>

    inside my content-home.php file custom template, which then I load in via the page attributes of the WordPress page. So now the text “Testing Something Crucial on my site” shows up on the page the home page as a matter of fact.

    Then when I go to search for that text, there’s no indication, that it exists anywhere. I rebuilt the index again after adding the filter.

    So same concept for ACF, I create a custom post type and build my fields in my custom post type, and then echo the functions in either the default template or a different custom template, then load the template in through the WordPress page editor page attributes metabox.

    Now by default you can configure Relevanssi to search acf fields and content, and ACF even has docs on how to do that without any help from Relevanssi too with their custom join function, and that’s nice, but both your suggestions including ACF’s only searches the custom post type, and that technically is where it was built, but I want them to see the page that the ACF widget is being output/loaded on, which is the home page, is what I am expecting in the search results not the custom post_type url.

    So for a basic example think about the function I have written above, then that it is echoed in a custom template.php file loaded in the page attributes, again not using the_content() function or the_excerpt() function and not pulling data from the database either. Am I using the filter correctly in that case? You see the string is not loaded in the database anywhere either.

    What I am expecting is since I have that testing_function() output on the home template file, so when I do a search for that string, it shows the Title of the Page which is home and even the excerpt of the entire home page too and the homepage link?

    Any other tips would be helpful to think about, like I said there is very little research on this topic.

    I know that I can build a bunch of shortcodes and add them to the page editor via tinymce from ACF and then it will likely work since it would then be going through the_content() function, but I prefer not to for a few reasons, its not a lazy thing, I would just prefer not to do it that way, it makes things look messy with tons of shortcodes in the editor and then certain containers for the output of the editor would break certain css too, I just don’t see why you can just build a function and echo it in the template and have it searchable. I wish WordPress had a good reason as to why, but Like I said this is a tough topic to find useful information on.

    Thanks again.

Viewing 8 replies - 1 through 8 (of 8 total)