Wordpress filters
add_filter('widget_text', 'do_shortcode');
add_action('pre_get_posts', 'archive_posts_per_page' );
function archive_posts_per_page( $wp_query ) {
if(is_archive() && is_main_query()) {
set_query_var('posts_per_page', 2);
}
}
add_shortcode('read-more', 'shortcode_read_more');
function shortcode_read_more($atts){
global $post;
extract(shortcode_atts(array('url' => get_permalink($post->ID),'text' => 'Button sample', 'class' => 'holder'), $atts));
return '<div class="'.$class.'"><a class="button" href="'.$url.'">'.$text.'</a></div>';
}
add_filter('gform_get_form_filter','form_custom_filter',10,2);
function form_custom_filter($form_string, $form){
if($form['fields']['0']['formId'] == 3){
return str_replace(array('<ul','</ul>','<div class=\'gform_footer top_label\'>'),array('<ol','</ol>','<div class="gform_footer top_label"><span class="third-li">3</span>'), $form_string);
}else{
return $form_string;
}
}
----- read more filter
add_filter('the_content_more_link','more_link_custom_filter',10,1);
function more_link_custom_filter($link){
return '<div class="button-holder">'.str_replace(array('more-link','(more...)'),array('button','Read More'),$link).'</div>';
}
------ выводить посты по кастомфилду только по году
function wpa86916_filter_where($where)
{
$where = str_replace('CAST(wp_postmeta.meta_value AS DATE)','YEAR(CAST(wp_postmeta.meta_value AS DATE))', $where );
remove_filter( 'posts_where', __FUNCTION__ );
return $where;
}
if(!empty($_GET['nam']))
$args_filters['meta_query'][] = array('type' => 'DATE', 'key' => 'ngay_phat_hanh', 'value' => $_GET['nam'], 'compare' => '=');
add_filter( 'posts_where', 'wpa86916_filter_where' );
}
после квери поста wp_reset_query(); remove_filter( 'posts_where', 'wpa86916_filter_where' );