看起来这将实现您想要的功能,只需为其编写一个自定义函数:Custom field values in permalink
如下所示:如链接所示:
function jpb_custom_meta_permalink( $link, $post ){
$post_meta = get_post_meta( $post->ID, \'<insert your meta key here>\', true );
if( empty( $post_meta ) || !is_string( $post_meta ) )
$post_meta = \'<insert your default value (could be an empty string) here>\';
$link = str_replace( \'!!custom_field_placeholder!!\', $post_meta, $link );
return $link;
}
add_filter( \'post_link\', \'jpb_custom_meta_permalink\', 10, 2 );
您可以散列url并使用以下内容:
function append_sku_string( $link, $post ) {
$post_meta = get_post_meta( $post->ID, \'_sku\', true );
if ( \'product\' == get_post_type( $post ) ) {
$link = $link . \'#\' .$post_meta;
return $link;
}
}
add_filter( \'post_type_link\', \'append_sku_string\', 1, 2 );
将返回
http://example.com/product/productname#sku