Skip to content

Instantly share code, notes, and snippets.

View saxap's full-sized avatar
🙃

Sergey Astafev saxap

🙃
View GitHub Profile
@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////
@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 / set cookie wp
Created July 12, 2015 09:06
set global cookie wp
@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 / bootstrap_form_validation.js
Last active August 29, 2015 14:25
simple bootstrap form validation on jquery
function checkErrors(el) {
var errors = false
el.find('input, textarea').each(function(){
if ($(this).val() == '') {
$(this).closest('.form-group').addClass('has-error');
errors = true;
} else {
$(this).closest('.form-group').removeClass('has-error');
}
});
@saxap
saxap / exclude_children.php
Created August 3, 2015 11:18
exclude children posts from parent taxonomy term page
function exclude_children($wp_query) {
if (isset($wp_query->query_vars['tax_name'])) {
$wp_query->set('tax_query', array(array(
'taxonomy' => 'tax_name',
'field' => 'slug',
'terms' => $wp_query->query_vars['tax_name'],
'include_children' => false
)));
}
}
@saxap
saxap / waitfunctions.js
Created August 30, 2015 18:34
some functions..
var is_ajaxed = false;
$.ajaxSetup({
//async: false
});
$(document).ajaxSend(function() {
console.log( "is_ajaxed." );
is_ajaxed = true;
});
function remove_page_from_query_string($query_string) {
if (is_admin()) return $query_string;
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so i'm spliting it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
// yoast rel fixes
add_filter( 'wpseo_prev_rel_link', 'hide_it');
add_filter( 'wpseo_next_rel_link', 'hide_it');
function hide_it($str) {
if (is_home() || is_post_type_archive('services') || is_post_type_archive('reviews') || is_post_type_archive('contacts')) {
return false;
} else {
$search = array(
'pressroom/news/',
'pressroom/articles/'
// only published term
$args = array();
$args['posts_per_page'] = 99999999999;
$args['post_type'] = 'ask';
$args['tax_query'] = array('relation' => 'AND');
$args['tax_query'][] = array(
'taxonomy' => 'qstatus',
'field' => 'id',
'terms' => array(19),
'operator' => 'NOT IN'