add_rewrite_rule only works when flush first

Problem with rules occurs, because rule for a given projecttype is added when you visit relevant URL. Every time you visit one of projects/{projectstype}/ addresses and flush rewrite rules, they are deleted and only one rule (only for current project type) is saved/created. You can add your code to request filter hook, then there is … Read more

Add slug to default post permalinks ONLY

Literally found the answer 10 minutes after posting this question and spending a couple of hours on it before asking. Simply hook your function to post_link! 🤦 public function __construct() { add_action(‘post_link’, [$this, ‘post_links’], 10, 2); } public function post_links($link, $post) { if ($post->post_type === ‘post’) { return site_url(‘slug/’. $post->post_name .’-‘. $post->ID); } else { … Read more

Rewrite rule can’t get the ID from rewrited

Ok, you need to add the id param to the list of public query variables : add_filter(‘query_vars’, ‘query_vars’); function query_vars($public_query_vars) { $public_query_vars[] = ‘id’; return $public_query_vars; } Thanks to this plugin for the help : https://wordpress.org/plugins/monkeyman-rewrite-analyzer/#reviews

WordPress add_query_arg from ajax and make url friendly

This add_query_arg function is add argument after URL you have enter. You have to get pretty URL so add below code in your functions.php file : function custom_rewrite_rule() { add_rewrite_rule(‘^cars/([^/]*)/([^/]*)/?’,’index.php?page_id=PAGE_ID&type=$matches[1]&models=$matches[2]’,’top’); flush_rewrite_rules(); } add_action(‘init’, ‘custom_rewrite_rule’, 10, 0); function custom_rewrite_tag() { add_rewrite_tag(‘%type%’, ‘([^&]+)’); add_rewrite_tag(‘%models%’, ‘([^&]+)’); } add_action(‘init’, ‘custom_rewrite_tag’, 10, 0); add_action( ‘wp_ajax_get_prepare_link’, ‘prepare_link’); add_action( ‘wp_ajax_nopriv_get_prepare_link’, ‘prepare_link’); function … Read more

How to create multiple Rewrite-Rule for various site in single htaccess?

I’m currently using this- # TN – BEGIN https to https <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^scorewheel\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.scorewheel\.com$ RewriteRule .* https://scorewheel.com%{REQUEST_URI} [R=301,L] </IfModule> # TN – END http to https # TN – Begin cdn redirection <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^cdn.scorewheel\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.cdn.scorewheel\.com$ RewriteCond … Read more

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