Possible to add another setting to ‘Front page displays’ setting for Custom Post Type

It appears that the options-reading.php file is hard-coding its options, rather than using the Settings API.

And that option is using wp_dropdown_pages() specifically. The Codex lists the following arguments for wp_dropdown_pages():

<?php 
$args = array(
    'depth'            => 0,
    'child_of'         => 0,
    'selected'         => 0,
    'echo'             => 1,
    'name'             => 'page_id'); 
?>

The Codex page also indicates that this function theoretically can take any argument that can be passed to get_pages(), which includes a post_type argument:

<?php 
$args = array(
    'child_of'     => 0,
    'sort_order'   => 'ASC',
    'sort_column'  => 'post_title',
    'hierarchical' => 1,
    'exclude'      => ,
    'include'      => ,
    'meta_key'     => ,
    'meta_value'   => ,
    'authors'      => ,
    'exclude_tree' => ,
    'post_type' => 'page',
?>

…which means that theoretically wp_dropdown_menu() could be modified to return your Custom Post Type posts.

Note that wp_dropdown_pages() does have an output filter hook, wp_dropdown_pages:

$output = apply_filters('wp_dropdown_pages', $output);

…so maybe you could use the filter somehow to target the page_on_front select form field specifically:

wp_dropdown_pages( array( 'name' => 'page_on_front', 'echo' => 0, 'show_option_none' => __( '&mdash; Select &mdash;' ), 'option_none_value' => '0', 'selected' => get_option( 'page_on_front' ) ) ) );

EDIT

From this comment:

What I want to do is set a page as posts page for my CPT, just like you can do for posts

I’m still not sure that the core settings are really extensible in this manner, but you do have alternatives.

The most obvious one would be to create a custom Page template that is a “page for Posts”, in which you query your specific Custom Post Type.

Mostly copy-pasta from the Codex link; you’ll want to modify the markup to fit in with your Theme:

<?php
/**
 * Template Name: Case Studies
 */
?>

<?php get_header(); ?>

<div id="content">

<?php 
$type="case-studies"; // Use the correct CPT slug here
$args=array(
  'post_type' => $type,
  'post_status' => 'publish',
  'paged' => $paged,
  'caller_get_posts'=> 1 // do not show sticky posts
);
// This bit is a "hack" to allow pagination to work properly
$temp = $wp_query;    
$wp_query = null;
$wp_query = new WP_Query($args); 
?>

<?php

 get_template_part( 'loop', 'index' );
 // Restore the original $wp_query
 $wp_query = $temp
?>

</div><!-- #content -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Then, of course, just create a page, and assign it the “Case Studies” template.

Leave a Comment