Skip to content

Instantly share code, notes, and snippets.

View ideag's full-sized avatar

Arūnas Liuiza ideag

View GitHub Profile
@ideag
ideag / functions.php
Last active August 29, 2015 14:03
WordPress search in post_content *OR* post_meta, instead of *AND*
<?php
add_filter( 'posts_where' , 'klausk_search_where',100 );
function klausk_search_where( $where ) {
if (!is_admin() && is_main_query() && is_search()) {
$ex = explode( ' AND (', $where);
$meta_q = array_pop($ex);
$where = str_replace(' AND ('.$meta_q,'',$where);
$where = str_replace(')))',") OR ({$meta_q}))",$where);
}
return $where;
@ideag
ideag / functions.php
Last active August 29, 2015 14:03
filter post_types in search
<?php
add_filter('pre_get_posts','klausk_search_advanced');
function klausk_search_advanced($q=false){
if (!is_admin() && $q->is_main_query() && $q->is_search()) {
$q->set('post_type', array( 'post', 'question' ) );
}
return $q;
}
?>
@ideag
ideag / functions.php
Created July 10, 2014 09:24
Filter post_meta in WordPress searches
<?php
add_filter('pre_get_posts','klausk_search_meta');
function klausk_search_meta($q=false){
if (!is_admin() && $q->is_main_query() && $q->is_search()) {
$meta_query = array(
array(
'key' => 'klausk_answer',
'value' => like_escape($q->get('s')),
'compare' => 'LIKE',
),
@ideag
ideag / functions.php
Created July 10, 2014 15:21
get_template_part() replacement to fix variable scope problem in WordPress
<?php
function klausk_template_part($slug,$name=null) {
do_action( "get_template_part_{$slug}", $slug, $name );
$templates = array();
$name = (string) $name;
if ( '' !== $name )
$templates[] = "{$slug}-{$name}.php";
$templates[] = "{$slug}.php";
return locate_template($templates);
}
<?php
$args = array(
'category_name' => 'pavadinimas',
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
);
$myquery = WP_Query($args);
while ($myquery->have_posts()) :
$myquery->the_post();
@ideag
ideag / functions.php
Last active August 29, 2015 14:03
Proof of concept - offset get_posts/WP_Query by ID
<?php
class Klausk_Filter {
private $id = 0;
private $compare = '<';
public function __construct($id,$compare = '<') {
$this->id = intval($id);
$this->compare = $compare;
}
public function filter($where){
$where .= " AND `ID` {$this->compare} {$this->id}";
<?php
$post_id = 500
$p = get_post($post_id);
$args = array(
'date_query' => array(
'before' => $p->post_date,
// 'after' => $p->post_date
'inclusive' => true,
),
'exclude'=>$post_id
@ideag
ideag / delete.php
Created July 17, 2014 13:58
Remove WordPress nav menu item if asociated page is trashed
<?php
add_action( 'publish_to_trash', 'klausk_delete_menu_item' );
function klausk_delete_menu_item($post) {
// tik puslapiams
if( $post->post_type !== 'page' )
return;
// jei tema nepalaiko meniu - nieko daryti nereikia
if ( ! current_theme_supports( 'menus' ) ) { return; }
// trinamas meniu punktas
_wp_delete_post_menu_item($post->ID);
<?php
$slider_show = get_option('general_enable_slider');
$slider_auto = get_option('general_auto_play');
$slider_speed = get_option('general_slider_delay');
$slider_animation_time = get_option('general_animation_time');
if(empty($slider_speed)) {$slider_speed = "4000";}
if(empty($slider_animation_time)) {$slider_animation_time = "1000";}
if($slider_show[0] == 'yes') :
// if($slider_show[0] == 'yes') {
?>
@ideag
ideag / style.css
Last active August 29, 2015 14:04
.tiny_coffee_form button {
background-color:#000; /* pasirinkite norimą spalvą */
}