Problem with Redirect

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32437
    Patryk.Slowik35
    Patryk.Slowik35
    Participant

    Hello,
    I added a redirect as instructed by this code

    // Remove the line below, if you don't want to affect the Live results list
    add_filter( 'asp_results', 'asp_custom_link_meta_results', 10, 4 );
    // Remove the line below, if you don't want to affect the results page
    add_filter( 'asp_noajax_results', 'asp_custom_link_meta_results', 10, 4 );
    function asp_custom_link_meta_results( $results, $search_id, $is_ajax, $args ) {
        // Change this variable to whatever meta key you are using
        $meta_key = 'strona_odnoszaca';
    
        // --- DO NOT CHANGE ANYTHING BELOW ---
        foreach ($results as $k=>&$r) {
            if ( function_exists('get_field') )
                $new_url = get_field( $meta_key, $r->id, true ); // ACF support
            else
                $new_url = get_post_meta( $r->id, $meta_key, true );
    
            // Change only, if the meta is specified
            if ( !empty($new_url) ) {
                // Ajax results link
                if ( isset($r->link) ) {
                    $r->link = $new_url;
                }
                // Results page link
                if ( isset($r->asp_guid) ) {
                    $r->asp_guid = $new_url;
                }
            }
        }
    
        return $results;
    }

    But not everything works well. By typing a word in the menu search engine, when possible redirects are displayed, when you click on one it actually takes you to the page from ACF, it works.

    And after we click on it

    But when we click Enter and go to the Search Results page, when we click on topic, it still takes us to the selected articles.

    And after we click on it

    You can check this on my website

    http://ipo.projekt.e-direct.pl/

    #32461
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Unfortunately the search results page links in most cases can not be affected by the plugin. It tries to send it’s own links, but in most cases the theme takes over and changes it back.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #32462
    Patryk.Slowik35
    Patryk.Slowik35
    Participant

    So what are the possible solutions?
    Can I deactivate the search results page?
    Add some custom code?
    I would need urgent help with this problem

    #32476
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Custom code may not work, but directly editing the template file may actually be possible. There are template functions available.
    You could try finding the template part, where the search result URL is printed to the screen. Then replace the function, which prints the URL with this:

    the_asp_result_field('link');

    If all goes well, and nothing reset the query from earlier, then this should return the URL same as the live search.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.