Enqueue Script with URL parameters

WordPress can automatically add the query variables for you. Instead of directly writing the query arguments, you can use it this way: $args = array( ‘f’ => ‘j’, ‘s’ => ‘w’, ‘c’ => ‘t’ ); wp_enqueue_script( ‘param-example’, add_query_arg( $args, ‘https://domain.com/example’) ); This is your solution, since according to code reference, the return value is unescaped … Read more

Custom permalink with pagination

The problem is that your first rule is capturing anything that begins with news/archive/. Add the $ anchor to match only news/archive/: add_rewrite_rule( ‘^news/archive/?$’, ‘index.php?post_type=news&news_archive=true’, ‘top’ ); Your pagination rule will then begin to work as-is after you flush permalinks.

Passing Variable as URL Parameter — Security concerns?

Passing non-private/non-protected/non-sensitive values through the URL is quite widely used and a more reliable way of passing values from one page to another. The reason for this is, $_SERVER[‘HTTP_REFERER’] is totally unreliable and can never be trusted. It can also, in many case be an empty value. Check the two following posts for more details … Read more

Custom query_var causes displaying posts archive on front page

After detailed debugging of WP::parse_request() and WP_Query::parse_query() I found out that unset( $query_vars[‘date’] ); in ‘request’ filter helps. It basically unsets date query var before WP_Query::parse_query() is invoked so is_home() returns false. add_filter( ‘request’, function( $query_vars ) { global $wp_query, $wp; if ( ! $wp_query->is_main_query() ) { return $query_vars; } $qv_keys = array_keys( $wp->query_vars ); … Read more

Filtered query_vars becomes global. Why does this work?

Within the WP::parse_request() method (src) we locate the query_vars filter: $this->public_query_vars = apply_filters( ‘query_vars’, $this->public_query_vars ); and within WP::register_globals() we can see why it becomes globally accessible (src): // Extract updated query vars back into global namespace. foreach ( (array) $wp_query->query_vars as $key => $value ) { $GLOBALS[ $key ] = $value; } where the … Read more

paginate_links ignore my format

This part: ‘base’ => str_replace( 999999999, ‘%#%’, esc_url( get_pagenum_link( 999999999 ) ) ), is generating a page part like this one: ‘base’ => http://example.tld/page/%#%/ If we peek into paginate_links() we see the default: ‘base’ => $pagenum_link, // http://example.com/all_posts.php%_% : // %_% is replaced by format (below) ‘format’ => $format, // ?page=%#% : %#% is replaced … Read more