Skip to content

Instantly share code, notes, and snippets.

@scheurta
scheurta / asdf.js
Created January 10, 2018 11:31
adsf
app.select2 = {
init: function( el ) {
if ( 'undefined' === typeof el ) {
return;
}
var scope = this,
args = {
maximumSelectionLength: 1,
templateSelection: function( item ) {
muplugins_loaded
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_taxonomy
registered_post_type
registered_post_type
registered_post_type
registered_post_type
$category_arr = array();
$current_category = get_the_category();
foreach ( $current_category as $cat ) {
$category_arr[] = $cat->term_id;
}
$args = array(
'post_type' => 'cpt_name',
'post_status' => 'publish',
@scheurta
scheurta / prevent_delete_user.php
Last active August 29, 2015 14:10
Prevent deletion of specific user
// MY_USER_ID
define( 'MY_USER_ID', 7 );
/**
* Delete User action, checks for our defined user id
*
*/
function themename_delete_user( $id ){
if ( $id == MY_USER_ID ) {
wp_die( 'You cannot delete this user' );
@scheurta
scheurta / gravityformfield.php
Last active August 29, 2015 14:10
Gravity forms field
$form = get_field( 'gravity_form' );
if ( $form ) {
echo do_shortcode( '[gravityforms id="' . $form->id . '" title="false" description="false" ajax="true"]' );
}
@scheurta
scheurta / wp_query_optimized.php
Last active August 29, 2015 14:10
Optimized WP_Query for retrieving all posts
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'nopaging' => true, // remove if pagination is required
'no_found_rows' => true, // remove if pagination is required
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
@scheurta
scheurta / redirect empty searches.php
Last active August 29, 2015 14:10
WordPress - Redirect empty searches to search page
add_filter( 'pre_get_posts', function( $query ){
if ( isset( $_GET['s'] ) && empty( $_GET['s'] ) && $query->is_main_query() ) {
$query->is_search = true;
$query->is_home = false;
}
return $query;
});
@scheurta
scheurta / Polylang rewrite slugs
Created November 16, 2014 20:27
Polylang Rewrite Slugs
/**
* Post types slugs
*
*/
add_filter( 'pll_translated_post_type_rewrite_slugs', function( $post_type_translated_slugs )
{
$post_type_translated_slugs = array(
// cpt_name
'cpt_name' => array(