• Resolved preWeather

    (@preweather)


    Please help. Why Generate Press theme not working with custom variables?
    I add code in function.php

    function add_my_var($public_query_vars) {
        $public_query_vars[] = 'test';
        return $public_query_vars;
    }
    add_filter('query_vars', 'add_my_var');

    but url ……/?test=value show a Error : “Fatal error: Allowed memory size …”

Viewing 10 replies - 1 through 10 (of 10 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    You can try increasing your php memory limit: https://generatepress.com/knowledgebase/increasing-memory-limit/

    Does that error go away once you remove your custom code?

    Thread Starter preWeather

    (@preweather)

    Hi Tom ,
    I did it before and when increase php memory limit page get infinite loop.
    “Does that error go away once you remove your custom code? ” – custom code does not error on all pages, only on pages with custom variables with url …./?test=value

    Theme Author Tom

    (@edge22)

    Infinite loops generally means there’s an issue with the code.

    What is that code supposed to do?

    Thread Starter preWeather

    (@preweather)

    Thank you for answer.
    I would like work with $_GET, then rewrite it to nice url. It should be second custom search result page with custom nice url. Search result page look so now:
    https://astroson.com/search/%D0%90%D1%8D%D1%80%D0%BE%D0%BF%D0%BB%D0%B0%D0%BD
    I want overwrite /search/ to another “nice word” or keyword for search engines. And search result page should look like a post.

    I try local move site to GeneratePress theme, all work but not custom variables.

    Theme Author Tom

    (@edge22)

    Can you show me where you got that code from?

    You can make /search/ (this isn’t default, did you add code to get this?) anything you like.

    For example: https://wpengineer.com/2258/change-the-search-url-of-wordpress/

    Let me know ??

    Thread Starter preWeather

    (@preweather)

    Hi Tom,
    Looks like /search/ is default in wordpress , other keywords not working and redirect to homepage or 404 page, if i change code wp_redirect( site_url() . ‘/search/’ ….

    this code in functions.php

    /* nice search link
    ------------------------------------*/
    function true_rewrite_search_results_permalink() {
    	global $wp_rewrite;
    	if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
    		return;
    	if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/search/") === false && ! empty( $_GET['s'] ) ) {
    		wp_redirect( site_url() . '/search/' . urlencode( get_query_var( 's' ) ) );
    		exit;
    	}
    }
     add_action( 'template_redirect', 'true_rewrite_search_results_permalink' );
    
    //for special characters, cyrillic
    function true_urldecode_s($query) {
    	if (is_search()) {
    		$query->query_vars['s'] = urldecode( $query->query_vars['s'] );
    	}
    	return $query;
    }
    add_filter('parse_query', 'true_urldecode_s');

    and for BuddyPress in bp-custom.php

    define( 'BP_SEARCH_SLUG', 'searchresults' );

    this is why i try to code with custom variable

    Thread Starter preWeather

    (@preweather)

    Tom, You can make nice search link option for GeneratePress theme. I don’t know why WordPress themes not have this option. Nice search link is always better as /?s=

    Theme Author Tom

    (@edge22)

    /?s= is the default in WordPress.

    www.ads-software.com won’t allow any rewrites like the above in the WordPress themes they host, it can get a little too messy.

    Perhaps this will help?: https://coffeecupweb.com/how-to-change-search-permalink-in-wordpress/

    Thread Starter preWeather

    (@preweather)

    Thank you, Tom, i found the problem.
    As i told already, WordPress have default search permalink /search/

    global $wp_rewrite;
    echo $wp_rewrite->search_base;

    in theme will show it.

    Maybe i will create a little WordPress Plugin to set custom permalink to search.

    But if you can, please, make custom variables in your theme work.
    https://endlessgeek.com/2014/02/wordpress-pass-extra-variable-url-parameter/

    Theme Author Tom

    (@edge22)

    Awesome, glad you were able to figure it out ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom variables’ is closed to new replies.