Может кто-нибудь мне помочь?Это правило перезаписи работает на PHP 5.6, но больше не работает на PHP 7.2 по странной причине.Никаких ошибок PHP - это просто пустое пространство.
В настоящее время также используется Wordpress 5.1.
/* adds the post name and the post id to the permalink structure of a listing */
function listing_rewrite() {
global $wp_rewrite;
$queryarg = 'post_type=listing&p=';
$wp_rewrite->add_rewrite_tag('%list_id%', '([^/]+)', $queryarg);
$wp_rewrite->add_permastruct('listing', '/%postname%-L%list_id%/', false);
}
/* add the post name and the post id to the url for a listing */
function listing_permalink($post_link, $id = 0, $leavename, $sample) {
global $wp_rewrite;
if (get_post_type($id) == "listing") {
$post = &get_post($id);
if ( is_wp_error( $post ) )
return $post;
$newlink = $wp_rewrite->get_extra_permastruct('listing');
$newlink = str_replace("%list_id%", $post->ID, $newlink);
$newlink = str_replace("%postname%", $post->post_name, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}
return $post_link;
}
/* rewrite the urls to remove 'listing' and add -L%post_id% at the end */
add_action('init', 'listing_rewrite');
add_filter('post_type_link', 'listing_permalink', 1, 20);