AI Verified

Name

Display and Search Post ID

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

ActionSkills

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://actionskills.co

History

Last modified:

13/12/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Display and Search Post ID

 
                    
1function add_column( $columns ){
2 $columns['post_id_clmn'] = 'ID'; // $columns['Column ID'] = 'Column Title';
3 return $columns;
4}
5add_filter('manage_posts_columns', 'add_column', 5);
6 
7function column_content( $column, $id ){
8 if( $column === 'post_id_clmn')
9 echo $id;
10}
11add_action('manage_posts_custom_column', 'column_content', 5, 2);
12 
13/**
14 * Allows posts to be searched by ID in the admin area.
15 *
16 * @param WP_Query $query The WP_Query instance (passed by reference).
17 */
18add_action( 'pre_get_posts','wpse_admin_search_include_ids' );
19function wpse_admin_search_include_ids( $query ) {
20 // Bail if we are not in the admin area
21 if ( ! is_admin() ) {
22 return;
23 }
24 
25 // Bail if this is not the search query.
26 if ( ! $query->is_main_query() && ! $query->is_search() ) {
27 return;
28 }
29 
30 // Get the value that is being searched.
31 $search_string = get_query_var( 's' );
32 
33 // Bail if the search string is not an integer.
34 if ( ! filter_var( $search_string, FILTER_VALIDATE_INT ) ) {
35 return;
36 }
37 
38 // Set WP Query's p value to the searched post ID.
39 $query->set( 'p', intval( $search_string ) );
40 
41 // Reset the search value to prevent standard search from being used.
42 $query->set( 's', '' );
43}

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

Clear navigation classes

Added: 1 year ago

Last Updated: 1 year ago

Remove classes and ids from li in navigation

General

AI Verified

General

AI Verified

0

CSS Tour Menu

Added: 7 months ago

Last Updated: 3 weeks ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

0

Disable Comments

Added: 7 months ago

Last Updated: 1 week ago

General

AI Verified

0

Remove tag and category taxonomy

Added: 7 months ago

Last Updated: 7 months ago

Divi Builder

AI Verified

0

Divi - Disable Project CPT and Taxonomy

Added: 7 months ago

Last Updated: 1 week ago