CustomPress Permalinks are not working correctly

SLS needed.

Regardless of setting, the category permalinks for the custom post type are not working. Trying a plugin conflict test did not solve it.

  • SSTech
    • Site Builder, Child of Zeus

    The Level 2 and 3 of nested categories do not work, level 1 or the root categories appear to be working to the point that it returns a valid page, however, the page doesn’t show the post of the category. It just shows the most recent posts of all categories.

  • Predrag Dubajic
    • Support

    Hi SSTech,

    I had a look at your site and tested your default Post categories links without CustomPress active and I keep getting 404 page as well so it doesn’t look like this issue is specific to CustomPress itself and that you’re having issues with taxonomy links in general.

    Can you tell me if Post categories are working properly with default WP theme and when all other plugins are disabled?

    Best regards,

    Predrag

  • SSTech
    • Site Builder, Child of Zeus

    I tested it on another template, 2 actually, divi theme, and twenty seven. They both came back with can’t be found. I dont’ have any post to test, but even with it disabled plugins disabled, I am still getting the 404 error. I created a custom taxonomy that is <navigation> and that works as expected. so something is off with categories.

  • SSTech
    • Site Builder, Child of Zeus
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress
    ## WP Defender - Prevent information disclosure ##
    <FilesMatch ".(txt|md|exe|sh|bak|inc|pot|po|mo|log|sql)$">
    Order allow,deny
    Deny from all
    </FilesMatch>
    <Files robots.txt>
    Allow from all
    </Files>
    ## WP Defender - End ##

  • Predrag Dubajic
    • Support

    Hi SSTech,

    I must say that I’m quite out of ideas here as your settings and .htaccess seem to be in place.

    Could you try reinstalling your WordPress so we can see if it’s something related to that?

    You can do that by downloading fresh version from wp.org and then replacing old files with new ones but make sure to keep your current one wp-content folder as well as .htaccess and wp-config.php files.

    Make sure to have a full backup before doing this just so you stay on safe side.

    Best regards,

    Predrag

  • Scott
    • Site Builder, Child of Zeus

    Following-up… is there a Walkthrough on how to Properly Setup new Custom Post Types that will display the Post Category in the URL?

    ex: CPT is named “Insights” –>

    Hierarchical = True

    Has Archive: True, Custom Slug = insights

    Rewrite = True, Custom Slug = insights (? Allow Front Base, ? Pages)

    Permalinks set to: /category/postname/

    However, when a new Insight Post is created, the URL is /insight/articlename/ – it should be /insight/article-category/articlename/

    Thoughts?

  • Predrag Dubajic
    • Support

    Hi Scott,

    To have these permalinks in CPT there are some additional steps needed to get it working.

    You will need a CPT, let’s say cars, and a custom taxonomy, let’s use cars_tax for this example.

    In your CPT you would need to use this as the rewrite slug:

    CPT/%CPT_TAXONOMY%

    Of course, adjust the values for your CPT and taxonomy, if we look at the above example values it would be like this:

    cars/%cars_tax%

    After that create a mu-plugin and add this code inside:

    <?php
    add_filter( 'post_type_link', function( $link, $post ){

    if ($post->post_type != 'CPT'){
    return $link;
    }

    if ($cats = get_the_terms($post->ID, 'CPT_TAX')){
    $link = str_replace('%CPT_TAX%', array_pop($cats)->slug, $link);
    }

    return $link;
    }, 20, 2 );

    Replace CPT with your CPT name, and CPT_TAX with the taxonomy and that should do the trick.

    If you need further assistance with this please start a new ticket so we don’t spam original poster with email notifications about our responses :slight_smile:

    Best regards,

    Predrag

  • Eetu Bergman
    • WPMU DEV Initiate

    Hello,

    I used this approach on my website. This works well with the custom posts, which have a taxonomy. If they are without taxonomy, you´ll get error 400, because it returns the rewrite slug as it is written in the admin:

    CPT/%CPT_TAXONOMY%

    How can I get this to work also without custom posts without a taxonomy.

    All the best,

    Eetu

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.