How To Load All Posts From The Current Week
Using the following snippet, you will be able to load all posts from the current week.
1 2 3 4 5 6 |
// display posts as desired query_args = array( 'w' => date( 'W' ), 'year' => date( 'Y' ), ); $posts = get_posts( $query_args ); |
Source Snippet/Code: Christian Brückner
How To Remove Widgets From WordPress Dashboard
Using the following snippet, you will be able to remove widgets from WordPress dashboard.
1 2 3 4 5 6 7 |
//Remove unwanted widgets from Dashboard function remove_dashboard_widgets() { global$wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } add_action('wp_dashboard_setup', 'remove_dashboard_widgets'); |
Snippet Source/Credit: WP Guru
How To Add A Custom Message To The Editor Pane
Using the following snippet, you will be able to add a custom message to the editor pane.
1 2 3 4 5 6 7 8 9 |
function wptutsplus_text_after_title( $post_type ) { ?> <div class="after-title-help postbox"> <h3>Using this screen</h3> <div class="inside"> <p>Use this screen to add new articles or edit existing ones. Make sure you click 'Publish' to publish a new article once you've added it, or 'Update' to save any changes.</p> </div><!-- .inside --> </div><!-- .postbox --> <?php } add_action( 'edit_form_after_title', 'wptutsplus_text_after_title' ); |
Snippet Source/Credit: WP Tuts
How To Limit Posts Per Page On Search
The following snippet will let you limit posts per page on search.
1 2 3 4 5 6 |
function limit_posts_per_search_page() { if ( is_search() ) set_query_var('posts_per_archive_page', 20); } add_filter('pre_get_posts', 'limit_posts_per_search_page'); |
Snippet Source/Credit: WordPress.org
How To Log-in A WordPress User Programmatically
The following snippet will let you log-in a WordPress user programmatically.
1 2 3 4 5 6 7 8 9 10 |
function auto_login( $user ) { $username = $user; if ( !is_user_logged_in() ) { $user = get_userdatabylogin( $username ); $user_id = $user->ID; wp_set_current_user( $user_id, $user_login ); wp_set_auth_cookie( $user_id ); do_action( 'wp_login', $user_login ); } } |
Once done, now to log-in a user, just simply do the following:
1 |
auto_login( 'admin' ) |
Snippet Source/Credit: emoticode