M W A A

Directory MWAA


/**
 * Plugin Name: My PMPro Directory Widget
 * Description: Add widget to Member Directory page to filter results.
 */
class My_PMPro_Directory_Widget extends WP_Widget {

	/**
	 * Sets up the widget
	 */
	public function __construct() {
		parent::__construct(
			'my_pmpro_directory_widget',
			'My PMPro Directory Widget',
			array( 'description' => 'Filter the PMPro Member Directory' )
		);
	}

	/**
	 * Code that runs on the frontend.
	 *
	 * Modify the content in the <li> tags to
	 * create filter inputs in the sidebar
	 */
	public function widget( $args, $instance ) {
		// If we're not on a page with a PMPro directory, return.
		global $post;
		if ( ! is_a( $post, 'WP_Post' ) || ! has_shortcode( $post->post_content, 'pmpro_member_directory' ) ) {
			return;
		}
		?>
		<aside id="my_pmpro_directory_widget" class="widget my_pmpro_directory_widget">
			<h3 style-'color: #02D202;'class="widget-title">Filter by State</h3>
			<form>
				<ul>
					
					<li>
						<strong>State:</strong><br/>
						<?php
						// Set up values to filter for.
						$state = array(
							'act'  => 'ACT',
							'nsw'  => 'NSW',
							'nt'  => 'NT',
							'qld'   => 'QLD',
							'sa' => 'SA',
							'tas'   => 'TAS',
							'vic'   => 'VIC',
							'wa'   => 'WA',
						);
						foreach ( $state as $key => $value ) {
							// Check if this value should default to be checked.
							$checked_modifier = '';
							if ( ! empty( $_REQUEST['state'] ) && in_array( $key, $_REQUEST['state'] ) ) {
								$checked_modifier = ' checked';
							}
							// Add checkbox.
							echo '<input type="checkbox" name="state[]" value="' . $key . '"' . $checked_modifier . '><label> ' . $value . '</label><br/>';
						}
						?>
					</li>
					
					<li><input type="submit" value="Filter"></li>
				</ul>
			</form>
		</aside>
		<?php
	}

}

/**
 * Check $_REQUEST for parameters from the widget. Add to SQL query.
 */
function my_pmpro_directory_widget_filter_sql_parts( $sql_parts, $levels, $s, $pn, $limit, $start, $end, $order_by, $order ) {
	global $wpdb;

	

	// Filter results based on coat color if a color is selected.
	if ( ! empty( $_REQUEST['state'] ) && is_array( $_REQUEST['state'] ) ) {
		$sql_parts['JOIN'] .= " LEFT JOIN $wpdb->usermeta um_state ON um_state.meta_key = 'state' AND u.ID = um_state.user_id ";
		$sql_parts['WHERE'] .= " AND um_state.meta_value in ('" . implode( "','", $_REQUEST['state'] ) . "') ";
	}

	
	return $sql_parts;
}
add_filter( 'pmpro_member_directory_sql_parts', 'my_pmpro_directory_widget_filter_sql_parts', 10, 9 );

/**
 * Registers widget.
 */
function my_pmpro_register_directory_widget() {
	register_widget( 'My_PMPro_Directory_Widget' );
}
add_action( 'widgets_init', 'my_pmpro_register_directory_widget' );

/**
 * Remember filters being used while using "Next" and "Previous" buttons.
 *
 * @since 2020/06/25
 */
function my_pmpromd_pagination_url_filter_directory( $query_args ) {
	$directory_filters = array( 'state' );
	foreach ( $directory_filters as $directory_filter ) {
		if ( ! empty( $_REQUEST[ $directory_filter ] ) ) {
        		$query_args[ $directory_filter ] =  $_REQUEST[ $directory_filter ];
    		}
	}
	return $query_args;
}
add_filter( 'pmpromd_pagination_url', 'my_pmpromd_pagination_url_filter_directory' );// Paste or type your code here…

Viewing All Profiles

Showing 1-15 of 33 Results

Adrian Barry
Email Address
enquiries@swcaravanweighing.com.au
State
WA
Business
Southwest Caravan Weighing
Adrian Corker
Email Address
weightrite3@gmail.com
State
QLD
Business
Weightrite
Alex and Brenda Macdonald
Email Address
admin@therightweigh.com.au
State
NSW
Business
The Right Weigh
Andrew Cowell
Email Address
admin@onsiteweighbridge.com.au
State
SA
Business
Onsite Weighbridge
Andy Parker
Email Address
info@yourtowweight.com.au
State
VIC
Business
Your Tow Weight
Beric Clifford
Email Address
info@driveaweigh.com.au
State
VIC
Business
Drive A Weigh
Borgy's Weigh Me RV
Email Address
borgy@weighmerv.com.au
State
NSW
Business
Weigh Me RV
Brett and Rowena Hand
Email Address
rowena@brhand.com.au
State
ACT
Business
Capital Vehicle Weighing
Chris Houley
Email Address
info@thenomadweigh.com.au
State
WA
Business
The Nomad Weigh
Chris Nussey
Email Address
cfnweighyavan@gmail.com
State
QLD
Business
CFN Weigh Ya Van
Darrin Anderson
Email Address
weighmyrig@gmail.com
State
QLD
Business
Weigh Your Rig
Debbie Ogden
Email Address
yourweigh@mobilevehicleweighing.com.au
State
NSW
Business
Your Weigh Mobile Vehicle Weighing
Dion Henderson
Email Address
info@weighstation.com.au
State
VIC
Business
Weigh Station Mobile Caravan & Vehicle Weighing
Garry Donnellan
Email Address
geelongcaravanweighing@gmail.com
State
VIC
Business
Geelong Caravan Weighing
Gary Trotter
Email Address
gary@verifyyaweights.com.au
State
VIC
Business
Verify ya Weights

For peace of mind, choose a member of the MWAA to weigh your rig

Scroll to Top