Monthly Archives: February 2015

Post by custom days without array

This is under plugins function

http://wordpress.stackexchange.com/questions/54142/check-post-date-in-pre-get-posts

query_posts(array(
‘post_type’ => ‘movies’,
‘event_categories’ => $spot_category,
‘posts_per_page’ => -1
));

Now i add in functions.php using hook

http://devotepress.com/wordpress-coding/when-to-use-pre_get_posts-in-wordpress/#.VO8EaTWli1G

function popular_posts_weekly_custom($query) {
if (function_exists(‘vh_spotlight’)){
$today = getdate();
$query->set( ‘orderby’, ‘comment_count’);
$query->set( ‘day’, $today[‘mday’] );
}
}
add_action( ‘pre_get_posts’, ‘popular_posts_weekly_custom’ );

Popular posts by comments

<?php
$args = array( ‘post_type’ => ‘movies’,
‘posts_per_page’ => 10,
‘orderby’ => ‘comment_count’,
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo   the_title().'</br>’;
endwhile;
?>

Display plugin on frontend side if is active

/* if booking plugin is active */
function legalattorneys_shortcode(){
include_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
if(is_plugin_active(‘fastbook-responsive-appointment-booking-and-scheduling-system/fastbook.php’)) {
echo do_shortcode(‘[fastbook]’);
}
}

/* Display any where */

<?php legalattorneys_shortcode(); ?>

Sanitation(validation) in wordpress

Backend side:
For url and image:  esc_url_raw();
For text:           sanitize_text_field();
For email:          sanitize_email();

Frontend side:
For url and image:   esc_url();
For email and text:  esc_attr();

=========================================
/* Validation for uploaded image */

function advent_image_validation($advent_imge_url) {
$advent_filetype = wp_check_filetype($advent_imge_url);

$advent_supported_image = array(‘gif’, ‘jpg’, ‘jpeg’, ‘png’, ‘ico’);

if (in_array($advent_filetype[‘ext’], $advent_supported_image)) {
return $advent_imge_url;
} else {
return ”;
}
}
/* sanitation */
advent_image_validation(esc_url_raw($input[‘logo’]));

%d bloggers like this: