This file contains 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 | |
# Get a page by its template, and optionally by additional criteria | |
function crb_get_page_by_template($template, $additional_meta = array()) { | |
// the query for the page template | |
$meta_query = array( | |
array( | |
'key' => '_wp_page_template', | |
'value' => $template, |
This file contains 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 | |
# Recommended usage for get_posts() and other functions with similar querystring parameters | |
$args = array( | |
'post_type' => 'attachment', | |
'posts_per_page' => 5, | |
'post_status' => 'inherit', | |
'suppress_filters' => false, | |
); | |
$attachments = get_posts($args); | |
?> |
This file contains 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 | |
# DEPRECATED usage for get_posts() and other functions with similar querystring parameters | |
$args = 'post_type=attachment&posts_per_page=5&post_status=inherit&suppress_filters=false'; | |
$attachments = get_posts($args); | |
?> |
This file contains 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 get_largest_consecutive_number_array($array) { | |
$result = array(); | |
$total_elements = count($array); | |
foreach ($array as $key => $element) { | |
$temp = array($element); | |
$next_key = $key + 1; | |
while($next_key < $total_elements) { | |
if ($array[$next_key] === $array[$next_key - 1] + 1) { |
This file contains 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 | |
# Resolving WPML and Carbon_Field_Association incompatibilities | |
add_filter('get_terms', 'crb_fix_get_terms_wpml', 0); | |
function crb_fix_get_terms_wpml($terms) { | |
global $wp_filter, $sitepress; | |
if ( is_admin() && !empty($sitepress) && !empty( $wp_filter['get_terms'] ) ) { | |
foreach ($wp_filter['get_terms'] as $priority => $callbacks) { | |
foreach ($callbacks as $callback_key => $callback) { |
This file contains 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 | |
global $wpdb; | |
// total comments | |
$post_id = 10; | |
$total_comments = $wpdb->get_var( " | |
SELECT COUNT(meta_value) FROM $wpdb->commentmeta | |
WHERE comment_id = $post_id | |
AND meta_key = '_comment_rating' |
This file contains 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 | |
# Our available options | |
function crb_test_options() { | |
return array( | |
123 => array( | |
'id' => 123, // ID of the entry, value that is saved in the DB, should be the same as the array key. | |
'title' => 'Test Title', // title of the item, used for displaying the item in the admin | |
'type' => 'test', // type of the item, used for identifying this type of item | |
'subtype' => 'test item', // subtype of the item, in this solution it will be used only for presentation purposes |
This file contains 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
function incrementNumberAnimation($element) { | |
var from = $element.text(); | |
var to = $element.data('increment-to'); | |
$({number: from}).animate({number: to}, { | |
duration: $element.data('increment-duration'), | |
easing: 'swing', | |
step: function() { | |
$element.text(Math.ceil(this.number)); | |
} | |
}); |
This file contains 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
function isElementInViewport(el) { | |
if ( document.documentElement.clientWidth <= 767 && document.documentElement.clientHeight < document.documentElement.clientWidth ) { | |
return $(el).is(':visible'); | |
} | |
if (typeof jQuery === "function" && el instanceof jQuery) { | |
el = el[0]; | |
} |
This file contains 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 | |
use Carbon_Fields\Container\Container; | |
use Carbon_Fields\Field\Field; | |
add_action('carbon_register_fields', 'my_carbon_fields_setup'); | |
function my_carbon_fields_setup() { | |
Container::make('post_meta', 'test1') | |
->show_on_post_type('post') | |
->add_fields(array( | |
Field::make('complex', 'crb_test1')->add_fields(array( |
OlderNewer