I've created a post type called listing
and an accompanying archive page archive-listing.php
. When I navigate to /listings
, the archive page loads properly. However, I'd like the archive URL to be /marketplace
. I'm defining the rewrite
property below but it doesn't seem to be working. What am I missing?
register_post_type("listing",
array(
"menu_icon" => "dashicons-tag",
"labels" => array(
"name" => __( "Listings" ),
"singular_name" => __("Listing")
),
"public" => true,
"has_archive" => true,
"rewrite" => array("slug" => "marketplace"),
"supports" => array("title", "editor"),
"taxonomies" => array("listing_status")
)
);
php $postType = get_post_type(); $related = new WP_Query([ 'post_type' => $postType, 'posts_per_page' => 3, 'post__not_in' => [ $post->ID ], ]);
Let's start by adding the Posts block to display items from your custom post type. Simply drag and drop the Posts block in the Advanced section onto your page. By default, the posts block will display your blog posts. Click on the block settings and then select your post type under Query by Post Type section.
Custom Post Type Archives The term “Archive” refers to a list of entries like post types, categories, and tags. To display archives on your website, they must be enabled for a custom post type. You will usually find the URL of your custom post type archive looking like this: http://example.com/post-type-slug/
You can also use:
'has_archive' => 'marketplace'
That way the slug of the archive page will be /marketplace and the single page will be /listing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With