Tag Info

New answers tagged

-1

Thanks, just what I needed after chaning the foldername (aka customer type name) I got too many 404. so I did: <IfModule mod_alias.c> RedirectMatch 301 /old_custom_post_type/(.*) /new_custom_post_type/$1 </IfModule>


0

From the documentation IMPORTANT: By default, WordPress will not recognize custom querystring variables used for rewrites. You must register your querystring variables with WordPress. Simply use add_rewrite_tag() to capture querystring variable values after a rewrite, or the above rewrite will not work! I believe WordPress is not recognizing ...


0

This exact piece of code works, the reason for redirect was some other plugin. To create as many child pages you want dynamically you just need to this just hook it to 'init' hook. add_action('init','my_custom_rewrite_rules' ); function my_custom_rewrite_rules(){ add_rewrite_tag( '%make%', '([^/]+)' ); ...


0

function my_custom_post_work() { $labels = array( 'name' => _x( 'Store', 'post type general name' ), 'singular_name' => _x( 'Store', 'post type singular name' ), 'add_new' => _x( 'Add New', 'Store' ), 'add_new_item' => __( 'Add New Store' ), 'edit_item' => __( 'Edit ...


0

You should use $_SERVER[] global array to get the url of the page. The simplified syntax is: $request_url=$_SERVER['REQUEST_URI']; You can then use the variable $request_url where you need the url.


0

have you looked at $_SERVER $real_address = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; echo $real_address; This code grabs your url with it's parameters and saves it to the $real_address variable Also have a look at this link here


0

There's a problem with your regex: product/(.+)/(.+)/(.+)/(.+)/?$ The .+ part says to match anything as many times as possible. The anything can include /'. If you used something like product/([^/]+/)+([^/]+)/?$ breaking this down, we have: product/ which matches product/ ([^/]+/)+? - which matches as few as possible, but at least 1, slug/ elements ...


0

You HAVE TO add a rewrite rule to WordPress. That can be done withou touching .htaccess. For example: add_action('init', 'cyb_rewrite_rule'); function cyb_rewrite_rule() { add_rewrite_rule( 'toto/([^/]+)/?$', 'index.php?pagename=$matches[1]', 'top' ); } If you need access to the second part of the URL as query var, you can do this: add_action('init', ...


0

Please check this plugin https://wordpress.org/plugins/rewrite/ It says that this plugin can create custom rewrite without having to touch PHP code


0

Alright, I solved it: I queried the year and month of the page we're on with: $year = get_query_var('year'); $monthnum = get_query_var('monthnum'); And then I added date parameters to each WP_Query: $col1 = new WP_Query( array( 'year' => $year, 'monthnum' => ...


0

You're currently placing your rewrite rules in the global scope, which means they execute as soon as your file is loaded, which may be too early. Instead try adding them on the init hook, or rewriting them to use the generate_rewrite_rules filter instead, e.g.: add_action('generate_rewrite_rules', 'themes_dir_add_rewrites'); function ...


1

That's why the last line of the get_admin_url contains the line: return apply_filters( 'admin_url', $url, $path, $blog_id ); Any valid modification of the admin URL will be via that filter, so get_admin_url is the correct function to use in all cases.


1

You can filter page_link to modify the output of any page's permalink value. The simplest way to identify the page is by ID, then you can append the query string via add_query_arg: function wpd_append_query_string( $url, $id ) { if( 42 == $id ) { $url = add_query_arg( 'ngg_force_update', 1, $url ); } return $url; } add_filter( ...


0

Well, I found the solution. It seems that, when applying a rewrite rule on a custom post type post, one needs to tell WP the custom post type's name within the rewrite rule itself. Here's the code that does NOT work (redirects and drops parameter variables instead of rewrite): function add_rewrite_rules($rules) { $newrules = ...


0

Search for the add_rewrite_tag function. You have to add a tag to catch up any variable in a rewrite; or it'll be dropped In your case, this should do the trick: add_rewrite_tag( '%ps-cpt-parameter%', '([^/]+)'); add_rewrite_rule('post/([^/]+)/([^/]+)/?', 'index.php?p=$matches[1]&ps-cpt-parameter=$matches[2]', 'top' ); // And then you could get the ...



Top 50 recent answers are included