add_clean_index() wordpress function and usage

Home / WordPress / WordPress Wiki / add_clean_index() wordpress function and usage

add_clean_index( string $table, string $index )
Adds an index to a specified table.

Parameters

$table

(string) (Required) Database table name.

$index

(string) (Required) Database table index column.

Return

(true) True, when done with execution.

Sample Usage

Sometimes after a table has been created in a database, we find that it is advantageous to add an index to that table to speed up queries involving this table.

function wpdocs_mwb_make_fetch_fast()
{
    global $wpdb;
    // Add some Clean up indices
    add_clean_index( $wpdb->posts, 'post_name' );
    add_clean_index( $wpdb->categories, 'category_nicename' );
    add_clean_index( $wpdb->comments, 'comment_approved' );
    add_clean_index( $wpdb->posts, 'post_status' );
}

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments