Forked from liamhiggins22/gist:ac937f3e4839a20a58d1abf4cd64353b
Created
February 1, 2024 11:46
-
-
Save xenio/d00cf0669576f874d0c4576fe6e39a9b to your computer and use it in GitHub Desktop.
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
add_filter( 'bricks/setup/control_options', function( $control_options ) { | |
$control_options['queryTypes']['reviews'] = esc_html__( 'WP Social Ninja Reviews', 'pixite-reviews' ); | |
return $control_options; | |
} ); | |
add_filter( 'bricks/query/run', function( $results, $query_obj ) { | |
if ( $query_obj->object_type !== 'reviews' ) { | |
return $results; | |
} | |
global $wpdb; | |
$table_name = $wpdb->prefix . 'wpsr_reviews'; | |
$data = $wpdb->get_results( "SELECT reviewer_name, reviewer_url, reviewer_text, review_time FROM $table_name WHERE reviewer_text IS NOT NULL AND rating = 5 ORDER BY RAND() LIMIT 6" ); | |
if (empty($data)) { | |
return $results; | |
} | |
$output = []; | |
foreach ($data as $d) { | |
$review = [ | |
'reviewer_name' => $d->reviewer_name, | |
'reviewer_url' => $d->reviewer_url, | |
'reviewer_text' => $d->reviewer_text, | |
'review_time' => date('F j, Y', strtotime($d->review_time)) | |
]; | |
$output[] = $review; | |
} | |
return $output; | |
}, 10, 2 ); | |
add_filter( 'bricks/query/loop_object', function( $loop_object, $loop_key, $query_obj ) { | |
if ( $query_obj->object_type !== 'reviews' ) { | |
return $loop_object; | |
} | |
/* Usually you'd prepare a WP_Post object or something | |
* in here (see official documentation). | |
* In this specific case there is nothing to do here. | |
*/ | |
return $loop_object; | |
}, 10, 3 ); | |
function get_custom_loop_object_property( $name ) { | |
$loop_object = \Bricks\Query::get_loop_object(); | |
if ( ! $loop_object ) return false; | |
if ( ! is_array( $loop_object ) ) return false; | |
if ( ! array_key_exists( $name, $loop_object ) ) return false; | |
return $loop_object[$name]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment