Skip to content

Instantly share code, notes, and snippets.

@mvital
mvital / functions.php
Created November 25, 2016 10:56 — forked from gnistdesign/functions.php
Custom tax query
<?php
add_rewrite_rule(
'^result/([^/]*)/?([^/]*)$',
'index.php?pagename=result&style_slug=$matches[1]&gender_slug=$matches[2]',
'top' );
add_rewrite_tag('%style_slug%','([^/]*)');
add_rewrite_tag('%gender_slug%','([^/]*)');
@mvital
mvital / custom-search-acf-wordpress.php
Created January 9, 2017 15:54 — forked from jserrao/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request. I updated this original script with better documentation and XSS / SQL injection support.
/*
##############################
########### Search ###########
##############################
Included are steps to help make this script easier for other to follow
All you have to do is add custom ACF post types into Step 1 and custom taxonomies into Step 10
I also updated this work to include XSS and SQL injection projection
[list_searcheable_acf list all the custom fields we want to include in our search query]
@return [array] [list of custom fields]
@mvital
mvital / acf-link-picker-shortcode.php
Created January 11, 2017 12:24 — forked from khromov/acf-link-picker-shortcode.php
ACF Link Picker Shortcode
@mvital
mvital / ACF If Else field.php
Created January 11, 2017 12:26 — forked from jpcontrerasv/ACF If Else field.php
ACF If Else field
<?php if ( get_field( 'field_name' ) ): ?>
This is displayed when the field_name is TRUE or has a value.
<?php else: // field_name returned false ?>
This is displayed when the field is FALSE, NULL or the field does not exist.
<?php endif; // end of if field_name logic ?>
@mvital
mvital / functions.php
Created January 11, 2017 12:28 — forked from yratof/functions.php
ACF OEmbed with thumbnails
<?php
/* Pull apart OEmbed video link to get thumbnails out*/
function get_video_thumbnail_uri( $video_uri ) {
$thumbnail_uri = '';
// determine the type of video and the video id
$video = parse_video_uri( $video_uri );
// get youtube thumbnail
@mvital
mvital / excerpt-as-instant-article-subtitle.php
Created January 11, 2017 15:42 — forked from webdados/excerpt-as-instant-article-subtitle.php
Use WordPress post excerpt as Facebook Instant Article subtitle
<?php
/* Instant Articles (https://wordpress.org/plugins/fb-instant-articles/) - Use post excerpt as subtitle */
add_filter( 'instant_articles_subtitle', 'hf_instant_articles_subtitle' );
function hf_instant_articles_subtitle( $subtitle ) {
$excerpt = get_the_excerpt();
if ( trim($excerpt)!='' ) $subtitle = trim($excerpt);
return $subtitle;
}
@mvital
mvital / infinite-previous-next-looping.php
Created February 10, 2017 12:04 — forked from banago/infinite-previous-next-looping.php
Infinite next and previous post looping in WordPress
<?php
/**
* Infinite next and previous post looping in WordPress
*/
if( get_adjacent_post(false, '', true) ) {
previous_post_link('%link', '&larr; Previous Post');
} else {
$first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
echo '<a href="' . get_permalink() . '">&larr; Previous Post</a>';
wp_reset_query();
@mvital
mvital / wp-query-ref.php
Created February 10, 2017 15:33
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference.
*
* All credits go to luetkemj. Thanks!
*
* @author luetkemj <luetkemj@gmail.com>
* @author s3rgiosan <me@s3rgiosan.com>
*
* @see http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
@mvital
mvital / Mark parent navigation active when on custom post type single page Mark (highlight) custom post type parent as active item in Wordpress Navigation. When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
<?php
add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 );
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Getting the post type of the current post
@mvital
mvital / filterContactFormRecipient.php
Created May 18, 2017 08:44 — forked from apintocr/filterContactFormRecipient.php
Contact Form 7 - Conditionally Chance Recipient to Post Meta
<?php
/**
* Contact Form 7 - Conditionally Chance Recipient to Post Meta
*
* This function gets the current post id and grabs the desired meta to use
* it on the submited form data to change the recipient email conditionally.
* You can add some conditional checks to make sure the data is correct.
*
* @author António Pinto <apinto@vanguardly.com>
* @link https://gitlab.com/snippets/1662384