If you change a templae with the Quick Edit, the original template name is removed from the post list but the new name doesn’t replace it.
Just refresh the post list page.
]]>This plugin has been a must for a while now, i tiny clever idea that saves a lot of job on managing complex sites.
That’s why I was worried when it just stopped working. Today I could finally have a look at it and realized it’s probably not working since the release of 3.0.
As noted on this topic, $GLOBALS['pagenow']
is not available when the Filter_Page_By_Template class is initialized. After the fix from that topic, there’s no php warning but neither anything else happens because $GLOBALS['pagenow']
is null
.
I’ve been trying to fix it and it looks like the class instantiation must be done into a hook. Otherwise $GLOBALS['pagenow']
is not available.
add_action('init',function(){
new Filter_Page_By_Template();
});
This worked for me. But maybe it’s not the most appropriate hook. I’m not an expert on the topic. wp_loaded
worked as well.
I found a minor bug that is easy to resolve. There is a missing test for existence and value present of the $GLOBALS['pagenow']
property.
It manifests by a PHP Notice:
> Notice: Undefined index: pagenow in /wp-content/plugins/filter-page-by-template/filter-page-by-template.php on line 17
## Solution
- L17: if( $GLOBALS['pagenow'] == 'edit.php' ) {
+ L17: if( !empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'edit.php' ) {
I’d submit a PR if I could find a Github repo for the plugin.
]]>I’m not sure if this is a relatively new issue, or if I just never noticed it before, but the filtering menu is showing up at the top of the admin page for all post types, e.g. Posts and my custom post types, not just Pages. Since only Pages use page templates, that’s the only place it should appear.
There’s a pretty simple fix. In the file filter-page-by-template.php, lines 28-30, you should remove this conditional (using $GLOBALS
is discouraged anyway):
if ( $GLOBALS['pagenow'] === 'upload.php' ) {
return;
}
and replace it with this:
$current_screen = get_current_screen();
if ( !isset( $current_screen->post_type ) || $current_screen->post_type != 'page' ) {
return;
}
I’ve tested and confirmed this works to make the dropdown only appear on Pages, not other post types.
]]>To filter “non-templated” pages — the pages with the default WordPress page.php behavior — you need to modify the metaquery to:
array(
'meta_query' => array(
array(
'key' => '_wp_page_template',
//'value' => $template_files,
'compare' => 'NOT EXISTS',
)
),
)
I did that adding one more instance in the IF/ELSE statement on line #57. I created a new ELSEIF with “default”, just like the same as “all_missing”, and used the meta quert above. Please note I did comment out the VALUE and changed to “NOT EXISTS” only.
Regards!
G.
I’ve found a solution to this error in my case, but I wanted to alert you to it as it may cause the plugin to conflict with other plugins/themes.
My theme is using add_filter('posts_join')
and add_filter('posts_where')
to add Advanced Custom Fields data to the search. This involves injecting a LEFT JOIN of the wp_postmeta table into the query. Your plugin is also doing an INNER JOIN of wp_postmeta, resulting in this error.
I was able to fix this by giving the joined table a unique alias in my query. But you may also want to do that with your plugin, to help ensure that it doesn’t conflict with other plugins that may be out there.
Once I had this resolved, the plugin works great! Thanks!
]]>