Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
@kovshenin
kovshenin / functions.php
Created July 25, 2011 11:03
Default posts order by name in admin
<?php
/*
* This snippet overrides the default post ordering in the edit posts table (admin),
* while keeping other post ordering options (by clicking on the table headings)
* still available. Useful for CMS-like setups and could be tweaked for
* custom post types as well
*
* Konstantin Kovshenin
* http://theme.fm
*/
@kovshenin
kovshenin / functions.php
Created July 27, 2011 16:19 — forked from vbk/TE-modification
Code used in functions.php
<?php
/** Both color schemes **/
add_filter( 'twentyeleven_color_schemes', 'twentyeleven_color_schemes_both' );
add_action( 'twentyeleven_enqueue_color_scheme', 'twentyeleven_enqueue_color_scheme_both' );
function twentyeleven_color_schemes_both( $color_schemes ) {
$color_schemes['orange'] = array(
'value' => 'orange',
'label' => __( 'Orange', 'twentyeleven' ),
'thumbnail' => get_stylesheet_directory_uri() . '/orange.png',
@kovshenin
kovshenin / style-2.css
Created August 9, 2011 15:13
Twitter Blockquotes Styles
blockquote.tweet {
border-left: solid 4px #ccc;
padding-left: 8px;
}
@kovshenin
kovshenin / one.sql
Created September 28, 2011 09:59
SQL Query
mysql> explain SELECT SQL_CALC_FOUND_ROWS wp_posts.post_title FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( (wp_postmeta.meta_key = 'my-field' AND CONVERT(wp_postmeta.meta_value, CHAR) = 'some value') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10;
+----+-------------+-------------+--------+---------------------------------+----------+---------+---------------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+--------+---------------------------------+----------+---------+---------------------------+------+----------------------------------------------+
| 1 | SIMPLE | wp_postmeta | ref | post_id,meta_k
<?php
class Some_Plugin {
function previous_gallery_post_link() {
add_filter( 'posts_where', array( &$this, 'filter_where_date_lt' ) );
$previous = new WP_Query( array(
'post_type' => 'post',
'tax_query' => array(
'relation' => 'AND',
array(
<?php
function vtp_install_data() {
add_action( 'init', 'vtp_setup_terms', 11 );
}
register_activation_hook( __FILE__, 'vtp_install_data' );
function vtp_setup_terms() {
if ( ! term_exists( 'Customer', 'account_type' ) ) {
wp_insert_term( 'Customer', 'account_type');
function filter_where_this_week( $where ) {
$where .= " AND post_date >= '" . date( 'Y-m-d 00:00:00', strtotime( '-7 days', current_time( 'timestamp' ) ) ) . "' AND post_date < '" . date( 'Y-m-d 23:59:59', strtotime( '+0 days', current_time( 'timestamp' ) ) ) . "' ";
return $where;
}
<select name="account" id="account">
<?php foreach ( $accounts as $account ) :
<option value='<?php echo $account->ID; ?>' <?php selected( in_array( $account->ID ) ); ?> >
<?php echo $account->post_title; ?>
</option>
</select>
@kovshenin
kovshenin / query.sql
Created December 29, 2011 23:17
Change the year of all posts in a particular category to 2012
UPDATE wp_posts AS p
JOIN wp_term_relationships AS tr ON tr.object_id = p.id
JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
JOIN wp_terms AS t ON tt.term_id = t.term_id
SET p.post_date = REPLACE(p.post_date, YEAR(p.post_date), 2012)
WHERE t.slug = 'my-category-slug' AND tt.taxonomy = 'category';
@kovshenin
kovshenin / birthday.php
Created January 16, 2012 11:11
A birthday gift I got from my brother :)
<?php
require 'classes/household.php';
require 'classes/birthday.class.php';
require 'classes/birthday.boy.class.php';
require 'classes/friend.php';
$K = new Birthday_Boy();
foreach ( $K->check_phone()->check_im()->check_social() as $greetings ) {