Skip to content

Instantly share code, notes, and snippets.

@dboutote
dboutote / tect-bases-rewrite.php
Created January 25, 2018 20:30
Fix The Events Calendar 4.6 update for custom url slug
<?php
function filter_tribe_bases( $bases = array() ){
$rewriteSlug = sanitize_title( Tribe__Settings_Manager::get_option( ‘eventsSlug’, ‘events’ ) );
$bases[‘archive’] = array( $rewriteSlug );
return $bases;
}
add_filter( ‘tribe_events_rewrite_base_slugs’, ‘filter_tribe_bases’ );
@dboutote
dboutote / disable-custom-rest-routes.php
Created April 6, 2018 17:09
Filter the generated REST routes by filtering the show_in_rest arg in register_post_type function
<?php
function dbdb_unset_rest_routes( $args, $post_type ) {
$allowed_post_types = array( 'page', 'post', 'company', 'job' );
$allowed_post_types = apply_filters( 'dbdb_unset_rest_routes_types', $allowed_post_types );
if( in_array( $post_type, $allowed_post_types ) ){
return $args;
} else {
$args['show_in_rest'] = 0;
@dboutote
dboutote / query-by-meta.php
Created June 11, 2018 16:30
Querying content by a meta key
<?php
$args = array(
'meta_key' => '_affiliatedCompany',
'meta_value' => $companyID,
'post_type' => 'article',
'posts_per_page' => 20,
);
$r = new WP_Query( $args );
@dboutote
dboutote / date-range-query.php
Created September 9, 2020 21:31
Custom WP_Query to get posts from a specific date range from a range of years.
<?php
$dates = ['relation'=>'OR'];
$x = 1;
while( $x <= 5 ) :
$currentDate = new DateTime();
$previous_date = $currentDate->sub( new DateInterval( "P{$x}Y" ) );
$previous_year = $previous_date->format('Y');
$currentDate = new DateTime();