This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

URL’s not working correctly with Divi FAQ

Home Forums Product Support Forums Ajax Search Pro for WordPress Support URL’s not working correctly with Divi FAQ

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #55420
    Shelly RogersShelly Rogers
    Participant

    I have been using Ajax Search Pro for years and love it. But when I created a NEW instance dedicated for a new FAQ section, the url’s don’t work and all links get forwarded to the home page.

    I am using a separate ajax search instance on the page that is dedicated for health insurance FAQ’s, searching only in this category and this page. This DOES NOT affect the main search bars, just the new one I created – [ajax_search_pro_HEALTH_FAQ] – [wd_asp id=6].

    I am using the divi theme, with Divi FAQ Plugin With Structured Data from ET Premium. This FAQ creates unique url’s for each FAQ. When i click on the url, it takes the user to the FAQ page and scrolls down and opens the particular FAQ. Here is an example of a FAQ url that works correctly: https://www.nevadainsuranceenrollment.com/questions-faq/health-insurance-faq/#faq-item-what-is-a-health-insurance-subsidy.

    The issue is, with ajax search pro, when clicking on any of the FAQ results from within a search, it uses this url: https://www.nevadainsuranceenrollment.com/?wpt-faq=what-is-a-health-insurance-subsidy.

    The url from the ajax search is missing the category and post name “questions-faq/health-insurance-faq/”.

    This happens to be oddly similar to the setting I use for my custom permalinks, which I add this to all urls: Custom Structure – https://www.nevadainsuranceenrollment.com/%category%/%postname%/.

    Is there a way to add the category and post name to the ajax search results?

    #55421
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Thank you very much for all the details and your kind words!

    The search requests the URL for each element via the standard get_permalink function, which should always return the appropriate permalink registered to the element.
    I’m guessing that the structured data plugin is likely registering these URLs somewhere, but it may not be directly to that hook so it doesn’t propagate.

    There is very likely a way to somehow get that URL programmatically via a function. I have looked up the plugin documentation but I couldn’t find any API or function reference to start with.

    Can you please ask them via their support how to get the permalink programmatically via the FAQ ID? With that information I can construct a small custom coded snippet to replace the URLs with the ones generated by the plugin.

    #55505
    Shelly RogersShelly Rogers
    Participant

    Thanks for looking into this.

    This was the response from the developer.


    Hi Shelly,

    The Divi FAQ plugin does not output any permalink.

    We have a faq listing divi module which outputs the faq questions and answers on an accordian.

    FAQ is a custom post type and rest all functionality is standard WordPress.

    Hope it helps

    Regards,

    #55507
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Oh, that is a big shame. That basically means these URLs does not exist(?) and can’t be requested, probably generated on the frontend.

    Still, there might be a hope to brute force it via converting the title to a hash, but I’m not sure:

    add_filter(
    	'asp_results',
    	function ( $results, $id, $is_ajax, $args ) {
    		if ( $id != 6 ) {
    			return $results;
    		}
    
    		$to_hash = function ( $str ) {
    			$str = preg_replace('/\s+/', '-', strtolower($str));
    			return preg_replace('/[^A-Za-z0-9\-]/', '', $str);
    		};
    
    		// -- Do not change anything below --
    		foreach ( $results as $k => $r ) {
    			$r->link = 'https://www.nevadainsuranceenrollment.com/questions-faq/health-insurance-faq/#' . $to_hash($r->title);
    		}
    		return $results;
    	},
    	10,
    	4
    );

    Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    #55511
    Shelly RogersShelly Rogers
    Participant

    Thank you for that code. We are going in the right direction, because it does grab the category and page title now, but the individual FAQ id is off.

    This is the actual url of the FAQ:
    https://www.nevadainsuranceenrollment.com/questions-faq/health-insurance-faq/#faq-item-what-is-a-health-insurance-subsidy

    This is what ajax is pulling up:
    https://www.nevadainsuranceenrollment.com/questions-faq/health-insurance-faq/#what-is-a-health-insurance-subsidy

    So close….

    #55514
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Oh I see, so It needs to add the “faq-item-” as prefix. Try this:

    add_filter(
    	'asp_results',
    	function ( $results, $id, $is_ajax, $args ) {
    		if ( $id != 6 ) {
    			return $results;
    		}
    
    		$to_hash = function ( $str ) {
    			$str = preg_replace('/\s+/', '-', strtolower($str));
    			return preg_replace('/[^A-Za-z0-9\-]/', '', $str);
    		};
    
    		// -- Do not change anything below --
    		foreach ( $results as $k => $r ) {
    			$r->link = 'https://www.nevadainsuranceenrollment.com/questions-faq/health-insurance-faq/#faq-item-' . $to_hash($r->title);
    		}
    		return $results;
    	},
    	10,
    	4
    );
    #55515
    Shelly RogersShelly Rogers
    Participant

    Ernest,

    That works perfectly. Thank you.

    I’ve used your product for multiple sites for over 10 years and have never had a problem.
    But when I did have an issue (with another product), you fixed it.

    Amazing product, amazing customer service.

    Thank you again,

    #55516
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #55517
    Shelly RogersShelly Rogers
    Participant

    I didn’t think about this, but what do I do when I add duplicate, then add this search bar to the “AUTO’ insurance FAQ page?
    I noticed the ‘health-insurance-faq’… is that for all search bars?
    I have one for the main site – searches everything.
    Then I have one for the health insurance FAQ section, auto FAQ, Homeowners FAQ etc.

    #55518
    Shelly RogersShelly Rogers
    Participant
    #55519
    Shelly RogersShelly Rogers
    Participant

    Can I change this to 8 (the auto id) = if ( $id != 6 ) {
    and change this to auto-insurance-faq (the auto url) = $r->link = ‘https://www.nevadainsuranceenrollment.com/questions-faq/health-insurance-faq/#faq-item-‘ . $to_hash($r->title);

    #55520
    Shelly RogersShelly Rogers
    Participant

    I tried it and it works.
    Thanks again for all the help.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.