Last active
November 29, 2023 14:06
-
-
Save LC43/8b4ea6dbe0fe59e8579c75f7646b9635 to your computer and use it in GitHub Desktop.
Revisions
-
LC43 revised this gist
Nov 29, 2023 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ <?php /** * ******* * Interactive Geo Maps user filter @@ -39,23 +40,22 @@ function add_author_filter_to_igmap_list() { // Ensure we're on the 'igmap' custom post type if ( $typenow === 'igmap' ) { // Get all posts of the specified Custom Post Type $args = array( 'post_type' => 'igmap', 'posts_per_page' => 500, 'fields' => 'all', 'suppress_filters' => true, // Ignore pre_get_posts hooks ); $cpt_entries = new WP_Query( $args ); // If there are posts, retrieve the unique authors $authors = []; if ( $cpt_entries->have_posts() ) { foreach ( $cpt_entries->posts as $post_entry ) { $author_id = $post_entry->post_author; if ( ! empty( $authors[ $author_id ] ) ) { ++$authors[ $author_id ]->igmaps_count; continue; @@ -80,7 +80,7 @@ function add_author_filter_to_igmap_list() { } } } add_action( 'restrict_manage_posts', 'add_author_filter_to_igmap_list', 999 ); // Modify the query based on the selected author filter function filter_igmap_by_author( $query ) { -
LC43 revised this gist
Nov 29, 2023 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,11 +43,12 @@ function add_author_filter_to_igmap_list() { $cpt_slug = 'igmap'; // Get all posts of the specified Custom Post Type $args = array( 'post_type' => $cpt_slug, 'posts_per_page' => -1, 'fields' => 'ids', // Only retrieve post IDs for efficiency ); $cpt_entries = new WP_Query( $args ); // If there are posts, retrieve the unique authors -
LC43 revised this gist
Nov 29, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ <?php /** * ******* * Interactive Geo Maps user filter -
LC43 revised this gist
Nov 29, 2023 . 1 changed file with 66 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,62 +1,94 @@ /** * ******* * Interactive Geo Maps user filter * ******************************** */ add_filter( 'manage_igmap_posts_columns', 'igmaps_cols', 11 ); function igmaps_cols( $columns ) { $columns['author'] = 'Author'; $columns['date'] = 'Date'; $columns['last_edited'] = 'Last Edited'; return $columns; } // Display the content of the Last Edited column function display_last_edited_column_content( $column, $post_id ) { // Display the last edited date for the post if ( $column == 'last_edited' ) { $last_edited = get_the_modified_date( 'Y-m-d H:i:s', $post_id ); echo $last_edited; } } add_action( 'manage_igmap_posts_custom_column', 'display_last_edited_column_content', 10, 2 ); // Make the Last Edited column sortable function make_last_edited_column_sortable( $sortable_columns ) { $sortable_columns['last_edited'] = 'last_edited'; return $sortable_columns; } add_filter( 'manage_edit-igmap_sortable_columns', 'make_last_edited_column_sortable' ); // Add the filter dropdown to the 'igmap' custom post type function add_author_filter_to_igmap_list() { global $typenow; // Ensure we're on the 'igmap' custom post type if ( $typenow === 'igmap' ) { // Customize the CPT slug $cpt_slug = 'igmap'; // Get all posts of the specified Custom Post Type $args = array( 'post_type' => $cpt_slug, 'posts_per_page' => -1, 'fields' => 'ids', // Only retrieve post IDs for efficiency ); $cpt_entries = new WP_Query( $args ); // If there are posts, retrieve the unique authors if ( $cpt_entries->have_posts() ) { $authors = array(); foreach ( $cpt_entries->posts as $post_id ) { $author_id = get_post_field( 'post_author', $post_id ); if ( ! empty( $authors[ $author_id ] ) ) { ++$authors[ $author_id ]->igmaps_count; continue; } $authors[ $author_id ] = get_userdata( $author_id ); $authors[ $author_id ]->igmaps_count = 1; } } if ( ! empty( $authors ) ) { echo '<select name="igmap_author_filter">'; echo '<option value="">Filter by Author</option>'; foreach ( $authors as $author ) { $selected = isset( $_GET['igmap_author_filter'] ) && $_GET['igmap_author_filter'] == $author->ID ? 'selected' : ''; echo '<option value="' . $author->ID . '" ' . $selected . '>' . $author->display_name . ' ( ' . $author->data->igmaps_count . ' ) </option>'; } echo '</select>'; } } } add_action( 'restrict_manage_posts', 'add_author_filter_to_igmap_list' ); // Modify the query based on the selected author filter function filter_igmap_by_author( $query ) { global $pagenow; // Ensure we're on the 'edit.php' page and dealing with the 'igmap' custom post type if ( is_admin() && $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'igmap' && isset( $_GET['igmap_author_filter'] ) ) { $query->query_vars['author'] = $_GET['igmap_author_filter']; } } add_filter( 'parse_query', 'filter_igmap_by_author' ); -
LC43 revised this gist
Nov 22, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php add_filter( "manage_igmap_posts_columns", 'igmaps_cols' , 11 ); function igmaps_cols( $columns ) { $columns['author'] = 'Author'; $columns['date'] = 'Date'; -
LC43 revised this gist
Nov 22, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php add_filter( "manage_igmap_posts_columns", 'igmaps_cols' , 10 ); function igmaps_cols( $columns ) { $columns['author'] = 'Author'; $columns['date'] = 'Date'; -
LC43 created this gist
Nov 22, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ add_filter( "manage_igmap_posts_columns", 'igmaps_cols' , 999 ); function igmaps_cols( $columns ) { $columns['author'] = 'Author'; $columns['date'] = 'Date'; $columns['last_edited'] = 'Last Edited'; return $columns; } // Display the content of the Last Edited column function display_last_edited_column_content($column, $post_id) { // Display the last edited date for the post if ($column == 'last_edited') { $last_edited = get_the_modified_date('Y-m-d H:i:s', $post_id); echo $last_edited; } } add_action('manage_igmap_posts_custom_column', 'display_last_edited_column_content', 10, 2); // Make the Last Edited column sortable function make_last_edited_column_sortable($sortable_columns) { $sortable_columns['last_edited'] = 'last_edited'; return $sortable_columns; } add_filter('manage_edit-igmap_sortable_columns', 'make_last_edited_column_sortable'); // Add the filter dropdown to the 'igmap' custom post type function add_author_filter_to_igmap_list() { global $typenow; // Ensure we're on the 'igmap' custom post type if ($typenow == 'igmap') { $authors = get_users(['who' => 'authors']); if (!empty($authors)) { echo '<select name="igmap_author_filter">'; echo '<option value="">Filter by Author</option>'; foreach ($authors as $author) { $selected = isset($_GET['igmap_author_filter']) && $_GET['igmap_author_filter'] == $author->ID ? 'selected' : ''; echo '<option value="' . $author->ID . '" ' . $selected . '>' . $author->display_name . '</option>'; } echo '</select>'; } } } add_action('restrict_manage_posts', 'add_author_filter_to_igmap_list'); // Modify the query based on the selected author filter function filter_igmap_by_author($query) { global $pagenow; // Ensure we're on the 'edit.php' page and dealing with the 'igmap' custom post type if (is_admin() && $pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'igmap' && isset($_GET['igmap_author_filter'])) { $query->query_vars['author'] = $_GET['igmap_author_filter']; } } add_filter('parse_query', 'filter_igmap_by_author');