admin管理员组文章数量:1130349
I have the dropdown dynamically populated with the titles of my podcast post type and I can successfully apply a filter by selected a podcast title and clicking filter. However, when the page loads and I see my filtered list the dynamic dropdown does not get populated.
Any idea why this is happening?
Here's my code pulled from my ThemeHelper class...
add_filter( 'parse_query', [ __CLASS__, 'parse_query' ] );
add_action( 'restrict_manage_posts', [ __CLASS__, 'restrict_manage_posts' ] );
function parse_query( $query ) {
global $pagenow;
// Change query based on post_parent
$parent_filter = $_GET['parent'];
if ( is_admin() && $pagenow == 'edit.php' && ! empty( $parent_filter ) ) {
$query->query_vars['post_parent'] = (int) $parent_filter;
}
}
public static function restrict_manage_posts() {
if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'episode' ) {
$args = [
'post_type' => 'podcast',
'numberposts' => - 1,
];
$podcasts = get_posts( $args );
$select = '<select name="parent"><option value="">Podcast (' . count( $podcasts ) . ')</option>';
foreach ( $podcasts as $podcast ) {
$selected = ( isset( $_GET['parent'] ) && (int) $_GET['parent'] > 0 ) ? 'selected="selected"' : '';
$select .= '<option value="' . $podcast->ID . '" ' . $selected . '>' . $podcast->post_title . '</option>';
}
$select .= '</select>';
echo $select;
} else {
return;
}
}
I have the dropdown dynamically populated with the titles of my podcast post type and I can successfully apply a filter by selected a podcast title and clicking filter. However, when the page loads and I see my filtered list the dynamic dropdown does not get populated.
Any idea why this is happening?
Here's my code pulled from my ThemeHelper class...
add_filter( 'parse_query', [ __CLASS__, 'parse_query' ] );
add_action( 'restrict_manage_posts', [ __CLASS__, 'restrict_manage_posts' ] );
function parse_query( $query ) {
global $pagenow;
// Change query based on post_parent
$parent_filter = $_GET['parent'];
if ( is_admin() && $pagenow == 'edit.php' && ! empty( $parent_filter ) ) {
$query->query_vars['post_parent'] = (int) $parent_filter;
}
}
public static function restrict_manage_posts() {
if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'episode' ) {
$args = [
'post_type' => 'podcast',
'numberposts' => - 1,
];
$podcasts = get_posts( $args );
$select = '<select name="parent"><option value="">Podcast (' . count( $podcasts ) . ')</option>';
foreach ( $podcasts as $podcast ) {
$selected = ( isset( $_GET['parent'] ) && (int) $_GET['parent'] > 0 ) ? 'selected="selected"' : '';
$select .= '<option value="' . $podcast->ID . '" ' . $selected . '>' . $podcast->post_title . '</option>';
}
$select .= '</select>';
echo $select;
} else {
return;
}
}
本文标签: filtersHaving issue with dynamic data within restrictmanageposts function
版权声明:本文标题:filters - Having issue with dynamic data within restrict_manage_posts function 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749100884a2315972.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论