I need to change link that appear as http://localhost/product/happy-ninja/ to http://localhost/product/happy-ninja?product=$product_id and the code in the content-product.php look like this(line 44):
我需要将显示为http:// localhost / product / happy-ninja /的链接更改为http:// localhost / product / happy-ninja?product = $ product_id,content-product.php中的代码如下所示(第44行):
<a href="<?php the_permalink($product_id); ?>">
how to add the part ?product=
Thanks for your help
如何添加零件?产品=感谢您的帮助
1 个解决方案
#1
You could modify the permalink with the post_link filter
您可以使用post_link过滤器修改永久链接
I have not tested it but this code might works:
我还没有测试过,但是这段代码可能有效:
function append_query_string( $url, $post, $leavename ) {
if ( $post->post_type == 'product' ) {
$url = add_query_arg( 'product', $post->ID, $url );
}
return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );
#1
You could modify the permalink with the post_link filter
您可以使用post_link过滤器修改永久链接
I have not tested it but this code might works:
我还没有测试过,但是这段代码可能有效:
function append_query_string( $url, $post, $leavename ) {
if ( $post->post_type == 'product' ) {
$url = add_query_arg( 'product', $post->ID, $url );
}
return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );