Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having a very specific issue on permalinks. I have a custom post type and a taxonomy. Using the function below sorted out the correct structure of the taxonomy permalinks.

    function phototype_permalink($permalink, $post_id, $leavename){
        if (get_option('permalink_structure') != ''){
            $post = get_post($post_id);
            $rewritecode = array(
                '%postname%'
            );
            if (strpos($permalink, '%postname%') !== FALSE){   
                $terms = wp_get_object_terms($post->ID, 'phototype');  
                if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $phototype = $terms[0]->slug;
                else $phototype = '';
            }
            $rewritereplace = array(
                $phototype
            );
            $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
        } 
        return $permalink;
    }

add_filter('post_type_link', 'phototype_permalink', 1, 3);  

then adding this to args:

'rewrite' => array('slug' => '%postname%'),

Regular posts also fit themselves to the new structure. However I am getting 404 error on pages. The wierdest thing is that I am not getting this error on pages with parents.

For ex: I am getting 404 error here: domain.com/products-page/ and here not: domain.com/products-page/your-account/

Any idea?

share|improve this question

closed as too localized by toscho Jul 27 '12 at 22:34

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

Try adding 'with_front' => true or 'with_front' => false to your $args array after the slug. I had an issue with permalinks for a custom post type 404-ing yesterday and this solved it. Good luck!

share|improve this answer
Nope, both options did not work for me.. – jamiecim Dec 7 '11 at 15:42
You tried it as 'rewrite' => array('slug' => '%postname%', 'with_front' => false), right? Just making sure since I was not very clear. – Joseph Dec 7 '11 at 20:50
yes i tried exactly like that, but it does not have any effect on permalinks.. maybe you have another idea? – jamiecim Dec 8 '11 at 0:18
Sorry; I wish I knew what else to tell you... – Joseph Dec 8 '11 at 19:35

You can try flush your rewrite rules:

From WordPress Codex the description is:

"This method can be used to refresh WordPress' rewrite rule cache. Generally, this should be used after programmatically adding one or more custom rewrite rules."

Add to your functions.php and run once:

//Ensure the $wp_rewrite global is loaded
global $wp_rewrite;
//Call flush_rules() as a method of the $wp_rewrite object
$wp_rewrite->flush_rules();

Read more here.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.