• Hi guys, it will be my first time posting a question here and hope anyone can help me. Here’s my problem.

    Firstly, I had a wordpress site which has a custom post type with assigned custom fields and with those fields I customize the post’s permalink using the rewrite(). After doing that, posts are now working fine but as i go to page the content are all gone wrong. basically it shows the content of the homepage. All of the pages showed the same content.


    function add_rewrite_rules()
    {
    // Register custom rewrite rules
    global $wp_rewrite;
    $wp_rewrite->add_rewrite_tag('%booth_list%', '([^/]+)', 'booth_list=');
    $wp_rewrite->add_rewrite_tag('%state%', '([^/]+)', 'stated=');
    $wp_rewrite->add_rewrite_tag('%city%', '([^/]+)', 'cityd=');
    $wp_rewrite->add_permastruct('booth_list', '%state%/%city%/%booth_list%', false);
    }
    function permalinks($permalink, $post, $leavename)
    {
    $no_data = 'no-data';
    $post_id = $post->ID;
    if($post->post_type != 'booth_list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
    return $permalink;

    $state = sanitize_title_with_dashes(get_post_meta($post_id, 'state', true));
    $city = sanitize_title_with_dashes(get_post_meta($post_id, 'city', true));
    if(!$state) { $state = 'state'; }
    if(!$city) { $city = 'city'; }
    $permalink = str_replace('%state%', $state, $permalink);
    $permalink = str_replace('%city%', $city, $permalink);
    return $permalink;
    }
    add_action('init', 'add_rewrite_rules');
    add_filter('post_type_link', 'permalinks', 10, 3);

    Removing the code above will make the page back to normal.

    What may be the problem?

    Thanks

The topic ‘Rewrite() : Page's wrong content’ is closed to new replies.