Hi,
I have a website with a glossary on it. I have a page called domainname.com/glossary/ which is a standard 'page'. I have created a custom post type of 'jw_glossary' to store glossary items. I want the glossary items to appear under the glossary page so i would end up with a url structure like domainname.com/glossary/<item>.
In order to do this, I have created the glossary item custom post type like so:
function create_post_type_glossary() {
register_post_type( 'jw_glossary',
array(
'labels' => array(
'name' => __( 'Glossary Items' ),
'singular_name' => __( 'Glossary Item' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug'=>'glossary'),
)
);
}
My understanding is that if I were to use this line:
'rewrite' => array('slug'=>'glossary'),
I will be able to prepend the URL's for the glossary items with /glossary/ and give the illusion of them being below glossary in the site structure (/glossary/<item>). I have code on my /glossary/ page which lists links to the CPT's like so:
$args = array('post_type'=>'jw_glossary');
$loop1 = new WP_Query($args);
echo "<ul>";
while ( $loop1->have_posts() ) : $loop1->the_post();
echo "<li><a href='";
echo get_permalink();
echo "' title='";
echo the_title();
echo "'>";
echo the_title();
echo "</a></li>";
endwhile;
echo "</ul>";
}
These render the correct URLs (domainname.com/glossary/<item>) but when I click them and go through, I get a 404.
Am I going about this the correct way and if not, how do I make it so that the CPT pages sit below the /glossary/ in the URL?
Many thanks in advance for any solutions.