$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - CPT archive redirects to single post|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - CPT archive redirects to single post

matteradmin8PV0评论

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?

Share Improve this question asked Feb 21, 2019 at 7:33 labworxsalabworxsa 215 bronze badges 6
  • What does archive-livestreams.php look like? – Jacob Peattie Commented Feb 21, 2019 at 8:00
  • Is it a redirect to a specific post url? If yes, what is the url? – Robbert Commented Feb 21, 2019 at 8:05
  • @JacobPeattie here is the code I currently have in there. <?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
  • @Robbert not a specific url, seems to always go to the latest post created in the cpt, in this case it is: inthebunch.co.za/live-stream/live-stream-uae-tour, previously it redirected to inthebunch.co.za/live-stream/live-stream-volta-ao-algarve – labworxsa Commented Feb 21, 2019 at 8:33
  • What if you empty your archive-livestreams.php? – Robbert Commented Feb 21, 2019 at 8:41
 |  Show 1 more comment

1 Answer 1

Reset to default 0

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",
Post a comment

comment list (0)

  1. No comments so far