• Resolved paolofranzetti

    (@paolofranzetti)


    I have created a couple of custom functions in my functions.php to process a GET argument and pass it to a page

    add_filter( ‘query_vars’, ‘addnew_query_vars’, 10, 1 );
    function addnew_query_vars($vars)
    {
    $vars[] = ‘account’;
    return $vars;
    }
    add_action(‘init’, ‘custom_rewrite_basic’);
    function custom_rewrite_basic()
    {
    add_rewrite_rule(
    ‘^staff/([^/]+)([/]?)(.*)’,
    ‘index.php?pagename=staff&account=$matches[1]’,
    ‘top’
    );
    }

    Within the page template I get the ‘account’ variable with

    $account = get_query_var( ‘account’ )

    However it stops working when I activate the Permalink Manager plugin. My guess is that the rewrite rules are overwritten by the plugin.

    Is there a way to process GET variables within the Permalink Manager plugin ?

    Thank you very much for any advice,
    Paolo

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi Paolo,

    could you send me a sample link where the query var is used? I will try to prepare a custom snippet to make it working.

    Best Regards,
    Maciej

    Thread Starter paolofranzetti

    (@paolofranzetti)

    This is the main page:

    https://test.lambrate.inaf.it/test/

    and this is the URL that does not work (it redirects on the main page)

    https://test.lambrate.inaf.it/test/paolo.franzetti

    The “explicit” URL works fine;

    https://test.lambrate.inaf.it/index.php?pagename=test&account=paolo.franzetti

    Below I attached the “test” page source.

    This is the new site of my institute and it is password protected. I have created a temporary account for you;

    Username: test
    Password: ioNChi

    Thank you very much,
    Paolo

    ————————————————————————

    <?php
    /**
     * Template Name: Staff Page Template
     *
     * Displays the Personal Page Template.
     *
     * @package ThemeGrill
     * @subpackage Spacious
     * @since Spacious 1.0
     */
    get_header(); ?>
    
    	<?php do_action( 'spacious_before_body_content' ); ?>
    
    	<div id="primary">
    		<div id="content" class="clearfix">
    
    	<?php
    
    		$name = get_query_var( 'account' );
    		
    		if (strlen($name)!=0) {
    			
    			  print "This will be the page for the " . $name . " account";
    
    			} else {
    
    				print "This will be the full staff page";
    
    			}
    
    	?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    	<?php spacious_sidebar_select(); ?>
    
    	<?php do_action( 'spacious_after_body_content' ); ?>
    
    <?php get_footer(); ?>
    Plugin Author Maciej Bis

    (@mbis)

    Hi Paolo,

    could you try to disable “Canonical redirect” in Permalink Manager settings?

    Best regards,
    Maciej

    Thread Starter paolofranzetti

    (@paolofranzetti)

    Disabled, but still not working.

    Kind regards,
    Paolo

    Plugin Author Maciej Bis

    (@mbis)

    Hi Paolo,

    please add this code to your snippet:

    function pm_stop_redirect($request) {
    	if(!empty($request['account'])) {
    		$request['do_not_redirect'] = 1;
    	}
    
    	return $request;
    }
    add_filter('request', 'pm_stop_redirect', 999);

    Best regards,
    Maciej

    Thread Starter paolofranzetti

    (@paolofranzetti)

    I added the code in my “functions.php” (is this the right place?) but the direct URL still does not work.

    Paolo

    Plugin Author Maciej Bis

    (@mbis)

    Hi Paolo,

    do you possibly have any staging website where I can test it? If so, please send me the credentials to my email: contact /at/ maciejbis.net.

    Best regards,
    Maciej

    Thread Starter paolofranzetti

    (@paolofranzetti)

    Trying to setup a staging website for you, I realized that your solution actually works if I use the “real” page. I am not sure why… perhaps the “test” slug is some kind of reserved name…

    Anyway it works!

    Thank you again very much,
    Paolo

    It helped my problem! Thanks!

    function pm_stop_redirect($request) {
    	if(!empty($request['account'])) {
    		$request['do_not_redirect'] = 1;
    	}
    
    	return $request;
    }
    add_filter('request', 'pm_stop_redirect', 999);
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘GET arguments’ is closed to new replies.