I watched some tutorials and I renamed the “ plugins ” file but without success. I also tried to rename ” includes ” files and its also without succes.
I arrive at the file in question ( class-wc-auth.php?on line?60 ) but I do not know how to modify it to fix the error. I will be happy to put your advice into practice. Thanks in advance
]]>The code I use ( variation of https://wordpress.stackexchange.com/questions/182006/removing-parent-pages-from-permalink#answer-313280 ):
function my_pages_permalink( $link, $post_id) {
$slugname = get_post_field( 'post_name', $post_id, 'display' );
$slugname = $slugname."/";
$link = untrailingslashit( home_url($slugname) ) . '.html';
return $link;
}
add_filter( 'page_link', 'my_pages_permalink', 10, 3 );
What else should be done? Directives in .htaccess do not help. Some add_rewrite_rule has to be used? I have tried stuff like that:
function my_pages_permalink_rewrite() {
add_rewrite_rule('^(.+?)/(.+?)$', 'index.php?pagename=$matches[2]', 'top');
}
add_action('init', 'my_pages_permalink_rewrite');
but to no avail.
]]>I tried same thing using custom archive first, but with no result (the same behavior) so I switched to try with page.
Custom Post type uses Categories so I want to be able to show posts filtered by category. Idea is to use url to specify category like: ‘www.mydomain.com/sites/sports’.
I created
add_action( 'init', 'un_add_sites_rewrite_rule');
function un_add_sites_rewrite_rule() {
$rule = '^sites/(.+?)/?$';
$rewrite = 'index.php?pagename=sites&category_name=$matches[1]';
add_rewrite_rule($rule,$rewrite,'top');
};
After that, url www.mydomain.com/sites/sports works (no 404 error) but shows all posts, not filtered by category.
For some reason query_var category_name is not taken in consideration by QueryLoop. From what I learned so far QueryLoop should use category_name value if it is set.
I created action to investigate what happens on query:
add_action( 'pre_get_posts', 'un_test_posts_query' );
function un_test_posts_query( $query ) {
if ($query->query['post_type'] == 'site') {
echo "<pre>";
global $wp;
print_r ($wp->query_vars);
print_r ($query->query)
echo "<pre>";
}
This shows that var_query does contain category_name and it is properly populated as expected. But $query does not follow that.
Array
(
[category_name] => sports
[pagename] => sites
)
Array
(
[post_type] => site
[order] => ASC
[orderby] => title
[post__not_in] => Array
(
)
[offset] => 0
[posts_per_page] => 24
[tax_query] => Array
(
)
[meta_query] => Array
(
)
)
I am confused. Why this does not work?
]]>RewriteRule
lines added by the plugin in .htaccess
WordPress block:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteRule ^event-feed/? /blog/https://www.example.com/blog/wp-admin/admin-ajax.php?action=EventPostFeed [QSA,L]
RewriteRule ^eventpost/([0-9]*)\.(ics|vcs)? /blog/https://www.example.com/blog/wp-content/plugins/event-post/export/ics.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Website uses https://www.example.com/blog
as siteurl
and home
.
Problem seems to be add_rewrite_rule()
second parameter $query
which is provided as full URL instead of relative path to siteurl
and causes invalid /blog/https://www.example.com/blog/wp-...
entries.
public function init(){
add_rewrite_rule('event-feed/?', admin_url('admin-ajax.php?action=EventPostFeed'), 'top');
add_rewrite_rule('eventpost/([0-9]*)\.(ics|vcs)?', plugins_url('export/ics.php', __FILE__), 'top');
}
Use of admin_url()
and plugins_url()
here is wrong.
Fixing this might also require adjustments here, but we did not test further.
]]>Like this:
https://www.modeltrainprices.com/p/marklin-4430/ (English)
https://www.modeltrainprices.com/de/p/marklin-4430/ (German)
https://www.modeltrainprices.com/da/p/marklin-4430/ (Danish)
Problem is that sometimes all the non-English versions stop working and their urls return a 404, which I guess is because the rewrite rules get dropped.
I then need to run my add_rewrite_rule() calls again, and after these calls, the non-English versions work again.
Has any of you seen something like this before, i.e. where the rewrite rules get dropped a random intervals?
If yes, did you find a way to fix it?
Thanks,
Mads
custom-post
function rewrite_rules() {
$postName = "custom-post";
$postId = 123;
add_rewrite_rule(
$postName.'/?([^/]*)/', // also tried: '(?!.*elementor)'.$postName.'/?([^/]*)/?$',
'index.php?page_id=' . $postId.'&pid=$matches[1]&ptype='.$postName,
'top'
);
}
add_action('init', 'rewrite_rules');
Those parts work fine but I have trouble opening the custom post Elementor editor. When it opens
https://localhost/~test/wp-admin/post.php?post=1786&action=elementor
by clicking on “edit with Elementor” it will try to open https://localhost/~test/custom-post/demo/?elementor-preview=1786&ver=1658094603
. It fails with the error that it can’t find the_content
.
I’m using a custom theme and the theme pages do have the_content()
included.
Is there a way to prevent the Elementor editor to follow that add_rewrite_rule
? I’ve tried to use '(?!.*elementor)'.$postName.'/?([^/]*)/?$'
as a rule and in my regex tests it will only match the frondend URL
https://localhost/~test/custom-post/demo/
https://localhost/~test/custom-post/demo/?elementor-preview=1786&ver=1658094603
and not the elementor-preview URL but the editor still tries to follow the rule. If I remove the rule the Elementor editor will open correctly. So I would like to use that rule only for the frontend and make the backend ignore it.
]]>function rewrite_rules() {
$postName = "custom-post";
$postId = 123;
add_rewrite_rule(
$postName.'/?([^/]*)/',
'index.php?page_id=' . $postId.'&pid=$matches[1]&ptype='.$postName,
'top'
);
}
add_action('init', 'rewrite_rules');
This works fine BUT it breaks editing the post with Elementor in the backend.
Can I change the rule so that it will only work for the frontend? I’ve tried it with !is_admin() around it but then it won’t work in the frontend anymore.
The rewrite rule should only apply for “/custom-post/child1” to “fixed page” while viewing the post in the frontend not while I’m editing pages in the backend.
]]>add_action( 'init', function() {add_rewrite_rule( '^property/(.*)/units/([^/]+)/?$','index.php?property_units=$matches[2]','top' );});
It works well and its task is to add pages to units within a real estate project
But with polylang, it works for the default language only and does not work for other languages
]]>my page is:
domain.com/mypage/
my value is ‘myvalue’ in this page Similar below:
domain.com/mypage/myvalue
I want to get the amount of ‘myvalue’ on ‘mypage’ page, Please give me a complete code sample
Thank you for your answer
]]>function umame_rewrite_tag() {
add_rewrite_tag('%fwp_brands_kn%', '([^&]+)');
add_rewrite_tag('%fwp_dreng_produkttype%', '([^&]+)');
}
add_action('init', 'umame_rewrite_tag', 10, 0);
function umame_rewrite_rule() {
add_rewrite_rule('^m/kids/([^/]*)/([^/]*)/?','index.php?fwp_brands_kn=$matches[1]&fwp_dreng_produkttype=$matches[2]','top');
}
add_action('init', 'umame_rewrite_rule', 10, 0);
Hope there is some one there have a salution.
Best regards
Morten