Sort Query by post_in Parameter WordPress

Allows post queries to sort the results by the order specified in the post__in parameter. Just set the orderby parameter to post__in! add_filter( ‘posts_orderby’, ‘sort_query_by_post_in’, 10, 2 ); function sort_query_by_post_in( $sortby, $thequery ) { if ( !empty($thequery->query[‘post__in’]) && isset($thequery->query[‘orderby’]) && $thequery->query[‘orderby’] == ‘post__in’ ) $sortby = “find_in_set(ID, ‘” . implode( ‘,’, $thequery->query[‘post__in’] ) . “‘)”;… Continue reading Sort Query by post_in Parameter WordPress

Add custom javascript files to the wordpress site

Use wp_enqueue_script() in an init hook, or if in the admin only then in an admin_menu or admin_init hook. It might look something like this (which assumes you are calling from your theme’s functions.php file; note how I reference the stylesheet directory): <?php add_action(‘init’, ‘mysite_init’); function mysite_init() { $ss_url = get_bloginfo(‘stylesheet_directory’) wp_enqueue_script(‘mysite-scripts’,”$ss_url/js/mysite-scripts.js”); } That’s the basics. Pre-defined and Multiple Dependent Scripts But let’s say you… Continue reading Add custom javascript files to the wordpress site