I’ve been working hard at a system to upload articles to. Specifically via a custom post who’s URL changes based on an ACF selection field.

I’ve had great success, with users here helping me on the final push to fix 404 errors. but now, it seems that I’m stuck again. The parent pages seem to be uneditable, forcing the last 10 posts to show.

Here’s the setup. I have a Page who’s parenting structure is Community => Articles => Theories. the url is example.com/community/articles/theory/

When I visit that URL, it only displays the last 10 posts. Not custom posts, just regular posts.

The code I have to change permalinks for the Articles custom post type is this:

add_rewrite_tag( '%category_type%', '([^&]+)' );
register_post_type(
    'articles', array(
        'labels' => array(
            'name' => 'Articles',
            'singular_name' => 'Article',
            'add_new' => 'Add new article',
            'edit_item' => 'Edit article',
            'new_item' => 'New article',
            'view_item' => 'View article',
            'search_items' => 'Search articles',
            'not_found' => 'No articles found',
            'not_found_in_trash' => 'No articles found in Trash',
            ),
        'public' => true,
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'revisions',
            'thumbnail'
        ),
        'rewrite' => array('slug' => 'community/articles/%category_type%'),
        'menu_icon' => "dashicons-groups",
        'capability_type' => array('article','articles'),
        'map_meta_cap' => true,
    )
);

function rem_articles_rewrite( $post_link, $id = 0 ){
    $post = get_post($id);
    if ( is_object( $post ) ){
        $ptype=get_post_type($post);
        if($ptype=="articles"){

            $category=get_field('category',$post->ID);
            if( $category ){
                return str_replace( '%category_type%' , $category , $post_link );
            }
        }
    }
return $post_link;
}

That ensures articles appear at, for example, example.com/community/articles/theory/-ARTICLE_NAME-/. But I fear it’s also locking the example.com/community/articles/theory/ page, so I am unable to edit this page via the regular Page section, and somehow, it’s fallback isn’t a 404, but the last 10 posts of the site.

Is there anything that immediately jumps out at anyone? Something I’ve overlooked?

Thanks in advance for any reply!

Read more here: WordPress page not showing up – replaced with last 10 posts?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: