Ok, the title does not help too much, so let me try and explain.
It's a Genesis-based website.
I created a CPT:
function cptui_register_my_cpts_livestreams() {
/**
* Post Type: live streams.
*/
$labels = array(
"name" => __( 'Live streams', '' ),
"singular_name" => __( 'Live stream', '' ),
"menu_name" => __( 'Live streams', '' ),
"all_items" => __( 'All live streams', '' ),
"add_new" => __( 'Add new live stream', '' ),
"add_new_item" => __( 'Add new live stream', '' ),
"edit_item" => __( 'Edit live stream', '' ),
"view_item" => __( 'New live stream', '' ),
"view_items" => __( 'View live streams', '' ),
"search_items" => __( 'Search live streams', '' ),
"archives" => __( 'Live streams', '' ),
);
$args = array(
"label" => __( 'Live streams', '' ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => true,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "live-stream", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "thumbnail", "genesis-cpt-archives-settings", 'genesis-seo' ),
'yarpp_support' => true,
);
register_post_type( "livestreams", $args );
}
add_action( 'init', 'cptui_register_my_cpts_livestreams' );
I also created a file: archive-livestreams.php
For some unknown reason when I go to / it redirects me to the latest post created within that post type.
I cleared cache, re-saved permalinks etc... any advice?
Ok, the title does not help too much, so let me try and explain.
It's a Genesis-based website.
I created a CPT:
function cptui_register_my_cpts_livestreams() {
/**
* Post Type: live streams.
*/
$labels = array(
"name" => __( 'Live streams', '' ),
"singular_name" => __( 'Live stream', '' ),
"menu_name" => __( 'Live streams', '' ),
"all_items" => __( 'All live streams', '' ),
"add_new" => __( 'Add new live stream', '' ),
"add_new_item" => __( 'Add new live stream', '' ),
"edit_item" => __( 'Edit live stream', '' ),
"view_item" => __( 'New live stream', '' ),
"view_items" => __( 'View live streams', '' ),
"search_items" => __( 'Search live streams', '' ),
"archives" => __( 'Live streams', '' ),
);
$args = array(
"label" => __( 'Live streams', '' ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => true,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "live-stream", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "thumbnail", "genesis-cpt-archives-settings", 'genesis-seo' ),
'yarpp_support' => true,
);
register_post_type( "livestreams", $args );
}
add_action( 'init', 'cptui_register_my_cpts_livestreams' );
I also created a file: archive-livestreams.php
For some unknown reason when I go to https://inthebunch.co.za/live-stream/ it redirects me to the latest post created within that post type.
I cleared cache, re-saved permalinks etc... any advice?
The URL of your archive is https://inthebunch.co.za/livestreams/
.
Have a look at the docs for register_post_type
, specifically, the description for the has_archive
argument:
has_archive (boolean or string) (optional) Enables post type archives. Will use $post_type as archive slug by default. Default: false
In the case of your code, $post_type
is livestreams
:
register_post_type( "livestreams", $args );
If you want to change that value, you can supply a string for has_archive
:
"has_archive" => "live-stream",
<?php remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); add_action( 'genesis_entry_header', 'genesis_do_post_image', 8 ); genesis();
– labworxsa Commented Feb 21, 2019 at 8:31