Getting the different post statuses + count like in edit.php, in a custom submenu page

The class used in edit.php is an extension of the WP_List_Table: WP_Posts_List_Table. See wp-admin/includes/class-wp-posts-list-table.php. And here you find a call to wp_count_posts( $type=”post”, $perm = ” ). The first parameter is for the post type, the second can be empty or readable. If it is readable and the current user has no permission to see … Read more

Using pre_get_posts on a specific core/query block

A modified version of the suggestion from @birgire works. Note that this applies to the core/post-template block, not the core/query block. add_filter(‘block_type_metadata_settings’, function ($settings, $metadata) { if ($metadata[‘name’] !== ‘core/post-template’) { return $settings; } if ($settings[‘render_callback’] !== ‘render_block_core_post_template’) { return $settings; } $settings[‘render_callback’] = ‘wpse_render_block_core_post_template’; return $settings; }, 10, 2); function wpse_render_block_core_post_template($attributes, $content, $block) { … Read more

Using pre_get_posts to Filter Posts

You’re creating a new query, not altering the existing one. The pre_get_posts codex page has a note explaining that the $query argument is passed by reference and you should alter it directly. There’s no need to declare globals or return values. Update your function to be: add_action( ‘pre_get_posts’, ‘only_current’ ); function only_current( $query ) { … Read more

Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query

SOLUTION: I will post my solution and explain what was the problem and I hope that this post can help someone in the future. As we talk in the small comments the problem, was that I was sending a non existing taxonomy by error and this was causing the AND (0=1). To fix the whole … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)