Skip to content

Instantly share code, notes, and snippets.

View saxap's full-sized avatar
🙃

Sergey Astafev saxap

🙃
View GitHub Profile
@saxap
saxap / show first post by id
Created July 17, 2015 20:53
show first post by id wordpress (custom order by)
//in function.php
function filter_orderby_sticky( $order = '' ) {
global $wpdb;
//$first = pods('pods settings');
//$first = (int)$first->field( 'name of field' ); // if pods
return '('.$wpdb->prefix.'posts.ID = '.$first.') DESC, '.$wpdb->prefix.'posts.post_date DESC'; // $first is id of first post
}
// custom wp_query
add_filter( 'posts_orderby', 'filter_orderby_sticky' );
@saxap
saxap / set cookie wp
Created July 12, 2015 09:06
set global cookie wp
@saxap
saxap / parse youtube url
Created July 10, 2015 18:54
parse youtube url and return video id
function parse_youtube_url($url) {
$pattern = '#^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?:.+)?$#x';
preg_match($pattern, $url, $matches);
return (isset($matches[1])) ? $matches[1] : false;
}
@saxap
saxap / custom sort archive wordpress
Created July 10, 2015 17:33
change post ordering or post per page on archive pages wordpress
global $query_string;
query_posts( $query_string . '&posts_per_page=999&orderby=title&order=DESC' );
//if (have_posts()) : while (have_posts()) : the_post(); blablabla////