This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php /* | |
| Takes a product ID and returns an array that includes all types of variations of the product, and the attributes of that variation. | |
| Variations are normally returned as a term object. They belong to the original product ID and the taxonomy name is equal to the attribute name. | |
| If a custom variation is provided instead of a term object, the variation will simply be a string of the option's name. | |
| Example return result is given below. This is a single product with one attribute and two different variations. | |
| Array ( | |
| [pa_oregon-training-classes] => Array ( | |
| [attribute] => Array ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function my_maybe_woocommerce_variation_permalink( $permalink ) { | |
| if ( ! is_search() ) { | |
| return $permalink; | |
| } | |
| // check to see if the search was for a product variation SKU | |
| $sku = get_search_query(); | |
| $args = array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% set teamIdsToExclude = ['and'] %} | |
| {% for excerpt in craft.entries.section('team').limit(12) %} | |
| {% set teamIdsToExclude = teamIdsToExclude|merge([excerpt.id]) %} | |
| {% endfor %} | |
| {# Convert the teamIdsToExclude array into a comma separated list #} | |
| {% set teamIdsToExcludeString = teamIdsToExclude|join(', not ') %} | |
| {% for excerpt in craft.entries.section('team').id(teamIdsToExcludeString) %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Example meta box field | |
| $featured_categories->add_field( array( | |
| 'name' => __( 'Featured categories', 'iweb' ), | |
| 'id' => 'featured_categories', | |
| 'type' => 'pw_multiselect', | |
| 'options' => iweb_get_cmb_options_array_tax( 'category' ), | |
| ) ); | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Custom Loop Add to Cart. | |
| * | |
| * Template with quantity and ajax. | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. | |
| global $product; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function artigo_feed_rewrite( $wp_rewrite ) { | |
| $feed_rules = array( | |
| 'feed/artigos' => 'index.php?post_type=listing&feed=rss2' | |
| ); | |
| $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; | |
| } | |
| // regerar regras de permalinks depois de ativar / implementar esse código |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add custom post types main RSS feed. | |
| function wp_rss_feed( $query ) { | |
| if ( $query->is_feed() ) | |
| $query->set( 'post_type', array( 'post', 'events', 'books' ) ); | |
| return $query; | |
| } | |
| add_filter( 'pre_get_posts', 'wp_rss_feed' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Receive one array as input, filter values from it, and output as another array. | |
| // The function should loop through up to x iterations. | |
| // Credits go to the author of the answer here: http://stackoverflow.com/a/7274450/1152876 | |
| */ | |
| * Exit the foreach loop when count is reached. | |
| * Use a foreach to iterate over the full array, and if the stated maximum count isn't reached, process the whole array. | |
| * Otherwise, if the maximum iteration is reached, jump out of the loop. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Credit goes to authors of answers here: http://stackoverflow.com/a/2865393/1152876 | |
| <?php | |
| /* | |
| * Example array, the values are grabbed from a custom field on WordPress. | |
| * Works well if you need a solution that can accept any array. | |
| */ | |
| $array = get_post_meta( get_the_ID(), '_prefix_my_custom_field', true ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Easy! Using the example of a custom post type called ‘the_event’, | |
| * you’d just put the following into your functions.php file (or plugin). | |
| * Credits go to author: https://bay-a.co.uk/wordpress-tips/wp-api-v2-tips/ | |
| */ | |
| add_action( 'init', 'add_events_to_json_api', 30 ); | |
| function add_events_to_json_api(){ |