简体   繁体   中英

Wordpress Rewrite stops working on php 7.2

Can someone help me? This rewrite rule works on PHP 5.6, but no longer works on PHP 7.2 for odd reason. No PHP errors whatsoever its just white blank space.

Currently using Wordpress 5.1 as well.

/* 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);

Try changing this line:

add_filter('post_type_link', 'listing_permalink', 1, 20);

to

add_filter('post_type_link', 'listing_permalink', 1, 4);

You are currently suggesting that the callback will accept 20 arguments when it will actually only accept 4. These are supposed to match. ( https://developer.wordpress.org/reference/functions/add_filter/ ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM