Skip to content

Instantly share code, notes, and snippets.

add_action( 'pre_get_posts', 'mc_modify_query_rand_posts' );
function mc_modify_query_rand_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() )
$query->set( 'orderby', 'rand' );
}
<?php
function maor_twitter_run_wp_user_search_query() {
/* There's a reason we're adding the action from here, you'll see later why. */
add_action( 'pre_user_query', 'maor_twitter_help_main' );
/* Create a new WP_User_Query object, limit recordset to 10 */
$wp_user_search = new WP_User_Query(
array(
'number' => 10
<?php
/* [http://on.fb.me/UAe3H9] */
/*
* Posts that have the 'mc_order_key' custom field, and that their (numeric) value is low
* will be shown first. If you wish to reverse the order, change the 'order' parameter to
* 'DESC'. Also make sure to change the meta key.
*/
function mc_reorder_search_results( $query ) {
<?php
/* Plugin Name: P2 Force Login
* Description: Force logged-out users to log-in in order to view the P2
* Author: Maor Chasen
* Author URI: http://maorchasen.com/
* Version: 1.0
*/
function p2fl_force_login() {
is_user_logged_in() || auth_redirect();
@maor
maor / sliced-query.php
Created October 26, 2012 13:39
How WP queries date-based archives
if ( $q['m'] ) {
$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
$where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
if ( strlen($q['m']) > 5 )
$where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2);
if ( strlen($q['m']) > 7 )
$where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2);
if ( strlen($q['m']) > 9 )
$where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2);
if ( strlen($q['m']) > 11 )
@maor
maor / single-id-template.php
Created December 1, 2012 20:22
Add this to your functions.php or functionality plugin
<?php
function my_single_template_by_post_id( $located_template ) {
return locate_template( array( sprintf( "single-%d.php", absint( get_the_ID() ) ), $located_template ) );
}
add_filter( 'single_template', 'my_single_template_by_post_id' );
@maor
maor / jetpack-comments-rtl.css
Last active December 10, 2015 00:39
RTL support for Jetpack's Comments Module
/* RTL support for Jetpack's Comments Module */
body.rtl #respond form {
direction: rtl;
}
<?php
function roee_get_parent_page_title() {
global $post;
return ( ! empty( $post->post_parent ) ) ? get_the_title( $post->post_parent ) : false;
}
<?php
function illuminea_redirect_to_wordcamporg() {
if ( is_admin() )
return;
$year = date( 'Y' );
wp_redirect( "http://$year.jerusalem.wordcamp.org", 301 );
exit;
@maor
maor / wp3.5-attachments-filesize.php
Created January 27, 2013 10:52
Adds a new row that shows the file size under an individual attachment dashboard page
<?php
/**
* Adds a new row that shows the file size under an individual attachment dashboard page
*
* @author Maor Chasen
*/
function mc_attachment_submitbox_filesize() {
$post = get_post();
$filesize = @filesize( get_attached_file( $post->ID ) );