Add_rewrite_rule doesn’t seem to work?

ok this i didn’t know i had to “register” variable to use function my_add_rewrite_rules() { global $wp,$wp_rewrite; $wp->add_query_var(‘book_id’); add_rewrite_rule(‘^books/([^/]*)/reviews/([0-9]+)/?$’, ‘index.php?page_id=227&bookid_id=$matches[2]’, ‘top’); // Once you get working, remove this next line $wp_rewrite->flush_rules(false); } add_action(‘init’, ‘my_add_rewrite_rules’); and in page-reviews.php i am using $book_id = $GLOBALS[‘wp’]->query_vars[‘book_id’]; One last question: how do i fix my breadcrumbs as the books/…/reviews … Read more

Custom Endpoint For Custom Post Type from Child Theme

When you register your custom post type, you should use rewrite like this: add_action(‘init’, ‘create_location’); function create_location() { register_post_type(‘location’, array( ‘labels’ => array( ‘name’ => __(‘Locations’), ‘singular_name’ => __(‘Location’) ), ‘public’ => true, ‘rewrite’ => array( ‘slug’ => ‘location’ ) ) ); } Don’t forget to update your permalinks by going to example.com/wp-admin/options-permalink.php and click … Read more

Rewrite rule not passing variable

Try adding ‘source’ as an custom query var, rather than defining it as a rewrite tag. function wpse162627_add_query_vars( $query_vars ){ $query_vars[] = “source”; return $query_vars; } add_filter( ‘query_vars’, ‘wpse162627_add_query_vars’ ); function custom_url_source() { add_rewrite_rule( ‘^source/([^/]*)$’, ‘index.php?source=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘custom_url_source’);

How can I set up a secondary permalink structure?

I think I found a solution to this with a function that’s not commonly used: add_permastruct(). This does the trick of what I described above: add_rewrite_tag(‘%page%’,'([^/]+)’, ‘pagename=”); add_permastruct(“abc’,’/abc/%page%/’,false); add_rewrite_rule(‘abc/?$’,’index.php?page_id=6′,’top’); The add_rewrite_tag() defines the pagename value that I want WordPress to lookup. Then add_permastruct() defines my custom structure with that value. The last rule is just … Read more

add_rewrite_rule issues

The second one works because post_type=market triggers the market post type archive. Pages have no archive, so post_type=page in the first example doesn’t point to a valid destination. Rewrite rules have to ultimately result in a successful main query. For a specific page, you could use page_id or pagename.

Adding a custom rewrite rule for gallery/categories page

To answer my own question, I didn’t need to remove the ‘redirect_canonical’ filter, and I only needed to change the 2nd parameter for add_rewrite_rule. The resulting function looks as follows: function add_custom_rewrites() { add_rewrite_tag(‘%category%’, ‘(.+)’); add_rewrite_rule(‘^gallery/([^/]*)/?$’, ‘index.php?pagename=gallery&category=$matches[1]’, ‘top’); flush_rewrite_rules(); } add_action(‘init’, ‘add_custom_rewrites’);

HTTPS to HTTP rewrite rules not working as expected

The SSL admin and login redirection should be done through the FORCE_SSL_ADMIN constant in wp-config.php: define(‘FORCE_SSL_ADMIN’, true); For further information: Administration Over SSL Aditionally, if you want be redirected to http when you’re logged and in the frontend, take a look at: Redirect WordPress front end https URLs to http without a plugin

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)