Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




add_query_arg [ WordPress Function ]

add_query_arg ( No parameters )
Parameters:
  • (mixed) $param1 Either newkey or an associative_array
  • (mixed) $param2 Either newvalue or oldquery or uri
  • (mixed) $param3 Optional. Old query or uri
Returns:
  • (string) New URL query string.
Defined at:



Retrieve a modified URL query string.

You can rebuild the URL and append a new query variable to the URL query by using this function. You can also retrieve the full URL with query data.

Adding a single key & value or an associative array. Setting a key value to an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER value. Additional values provided are expected to be encoded appropriately with urlencode() or rawurlencode().

Source


<?php
function add_query_arg() {
    
$ret '';
    if ( 
is_arrayfunc_get_arg(0) ) ) {
        if ( @
func_num_args() < || false === @func_get_arg) )
            
$uri $_SERVER['REQUEST_URI'];
        else
            
$uri = @func_get_arg);
    } else {
        if ( @
func_num_args() < || false === @func_get_arg) )
            
$uri $_SERVER['REQUEST_URI'];
        else
            
$uri = @func_get_arg);
    }

    if ( 
$frag strstr$uri'#' ) )
        
$uri substr$uri0, -strlen$frag ) );
    else
        
$frag '';

    if ( 
preg_match'|^https?://|i'$uri$matches ) ) {
        
$protocol $matches[0];
        
$uri substr$uristrlen$protocol ) );
    } else {
        
$protocol '';
    }

    if ( 
strpos$uri'?' ) !== false ) {
        
$parts explode'?'$uri);
        if ( 
== count$parts ) ) {
            
$base '?';
            
$query $parts[0];
        } else {
            
$base $parts[0] . '?';
            
$query $parts[1];
        }
    } elseif ( !empty( 
$protocol ) || strpos$uri'=' ) === false ) {
        
$base $uri '?';
        
$query '';
    } else {
        
$base '';
        
$query $uri;
    }

    
wp_parse_str$query$qs );
    
$qs urlencode_deep$qs ); // this re-URL-encodes things that were already in the query string
    
if ( is_arrayfunc_get_arg) ) ) {
        
$kayvees func_get_arg);
        
$qs array_merge$qs$kayvees );
    } else {
        
$qs[func_get_arg)] = func_get_arg);
    }

    foreach ( (array) 
$qs as $k => $v ) {
        if ( 
$v === false )
            unset( 
$qs[$k] );
    }

    
$ret build_query$qs );
    
$ret trim$ret'?' );
    
$ret preg_replace'#=(&|$)#''$1'$ret );
    
$ret $protocol $base $ret $frag;
    
$ret rtrim$ret'?' );
    return 
$ret;
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics