Advanced Classifieds & Directory Pro Shortcodes

Below, you’ll find a detailed guide on how to add the Advanced Classifieds & Directory Pro Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Advanced Classifieds & Directory Pro Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Advanced Classifieds & Directory Pro Plugin and the shortcodes it provides:

Plugin Icon
Advanced Classifieds & Directory Pro

"Advanced Classifieds & Directory Pro is a versatile WordPress plugin that enables you to create and manage online classified ads and directories with ease and efficiency."

★★★★☆ (90) Active Installs: 3000+ Tested with: 6.2.3 PHP Version: 5.6.20
Included Shortcodes:
  • [acadp_categories]
  • [acadp_category]
  • [acadp_listings]
  • [acadp_locations]
  • [acadp_location]
  • [acadp_checkout]
  • [acadp_payment_errors]
  • [acadp_payment_receipt]
  • [acadp_payment_history]
  • [acadp_login]
  • [acadp_logout]
  • [acadp_register]
  • [acadp_user_account]
  • [acadp_forgot_password]
  • [acadp_password_reset]
  • [acadp_search_form]
  • [acadp_search]
  • [acadp_user_listings]
  • [acadp_user_dashboard]
  • [acadp_listing_form]
  • [acadp_manage_listings]
  • [acadp_favourite_listings]

Advanced Classifieds & Directory Pro [acadp_categories] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is a function that displays classified categories. It fetches and displays listings based on specific attributes like parent category, view, columns, depth, order, and more. The shortcode leverages the ACADP plugin settings for categories and listings. It enqueues the necessary style dependencies and then retrieves the terms related to ‘acadp_categories’. If terms exist and there are no errors, it generates content in either an image grid or text list view. If no results are found, it returns a ‘No results found’ message.

Shortcode: [acadp_categories]

Parameters

Here is a list of all possible acadp_categories shortcode parameters and attributes:

  • parent – ID of parent category to display its child categories
  • view – display format of categories, can be ‘text_list’ or ‘image_grid’
  • columns – number of columns to display in grid view
  • depth – level of category hierarchy to display
  • orderby – parameter to sort categories by
  • order – order direction, can be ‘ASC’ or ‘DESC’
  • show_count – whether to display the number of listings in each category
  • pad_counts – whether to include listings in child categories in count
  • hide_empty – whether to hide categories with no listings

Examples and Usage

Basic example – Display the categories in a text list view.

[acadp_categories view="text_list" /]

Advanced examples

Display the categories in a grid view with 3 columns, ordered by name in ascending order, and show the count of listings in each category.

[acadp_categories view="image_grid" columns="3" orderby="name" order="asc" show_count="1" /]

Display only the top-level categories (with parent ID 0), in a grid view with 4 columns, ordered by term ID in descending order, and hide the categories that have no listings.

[acadp_categories parent="0" view="image_grid" columns="4" orderby="term_id" order="desc" hide_empty="1" /]

Display the categories in a text list view, ordered by name in ascending order, show the count of listings in each category, and include the listings from child categories in the count.

[acadp_categories view="text_list" orderby="name" order="asc" show_count="1" pad_counts="true" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_categories] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_categories", array( $this, "run_shortcode_categories" ) );

Shortcode PHP function:

                    function run_shortcode_categories( $atts ) {	
		$shortcode = 'acadp_categories';

		$listings_settings   = get_option( 'acadp_listings_settings' );
		$categories_settings = get_option( 'acadp_categories_settings' );		
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// ...
		$attributes = shortcode_atts(
			array(
				'parent'     => 0,
				'view'       => ! empty( $categories_settings['view'] ) ? $categories_settings['view'] : 'text_list',
				'columns'    => $categories_settings['columns'],
				'depth'      => $categories_settings['depth'],
				'orderby'    => $categories_settings['orderby'], 
				'order'      => $categories_settings['order'],
				'show_count' => ! empty( $categories_settings['show_count'] ) ? 1 : 0,
				'pad_counts' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_categories', $listings_settings['include_results_from'] ) ? true : false,
				'hide_empty' => ! empty( $categories_settings['hide_empty'] ) ? 1 : 0
			),
			$atts
  		);
		
		$terms = get_terms( 
			'acadp_categories',
			array(
				'parent'       => (int) $attributes['parent'],
				'orderby'      => sanitize_text_field( $attributes['orderby'] ), 
				'order'        => sanitize_text_field( $attributes['order'] ),
				'hide_empty'   => ! empty( $attributes['hide_empty'] ) ? 1 : 0,			
				'hierarchical' => ! empty( $attributes['hide_empty'] ) ? true : false
			)
		);
		
		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
			// Backward compatibility (version < 1.7.3)	
			$categories_settings = $attributes;

			ob_start();
			if ( 'image_grid' == $attributes['view'] ) {
				include( acadp_get_template( 'categories/acadp-public-categories-image-grid-display.php' ) );
			} else {
				include( acadp_get_template( 'categories/acadp-public-categories-text-list-display.php' ) );
			}
			return ob_get_clean();		
		}

		return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-categories.php

Advanced Classifieds & Directory Pro [acadp_category] Shortcode

The Advanced Classifieds and Directory Pro shortcode is designed to display listings from specific categories. . It fetches the category using the ‘id’ attribute from the shortcode or the ‘acadp_category’ query variable. It then retrieves various settings and options to customize the display and ordering of listings. It enqueues necessary scripts and styles based on the view type. The shortcode also handles pagination and sets up a custom query to fetch the listings. If listings are found, it includes a template for displaying them. If no listings are found, it displays a ‘No results found’ message.

Shortcode: [acadp_category]

Parameters

Here is a list of all possible acadp_category shortcode parameters and attributes:

  • id – The unique identifier of the category
  • view – Defines the default view of listings
  • featured – Determines whether to show featured listings
  • filterby – Allows to filter listings
  • orderby – Sets the order of the listings
  • order – Defines the sorting order, ascending or descending
  • listings_per_page – Determines the number of listings per page
  • pagination – Enables or disables pagination
  • header – Controls the display of header

Examples and Usage

Basic example – This shortcode displays the ACADP category by referencing its ID.

[acadp_category id=1 /]

Advanced examples

Displaying the ACADP category with customized view, featured listings, and specific ordering. The shortcode will first try to load by ID, but if not found, it will try to load by slug.

[acadp_category id=1 view="list" featured=1 orderby="date" order="DESC" /]

Displaying the ACADP category with pagination and customized listings per page. The shortcode will first try to load by ID, but if not found, it will try to load by slug.

[acadp_category id=1 pagination=1 listings_per_page=10 /]

Displaying the ACADP category with a header and customized filter options. The shortcode will first try to load by ID, but if not found, it will try to load by slug.

[acadp_category id=1 header=1 filterby="featured" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_category] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_category", array( $this, "run_shortcode_category" ) );

Shortcode PHP function:

                    function run_shortcode_category( $atts ) {	
		$shortcode = 'acadp_category';

		$term_slug = get_query_var( 'acadp_category' );
		
		$term = '';
		
		if ( '' == $term_slug && ! empty( $atts['id'] ) ) {		
			$term = get_term_by( 'id', (int) $atts['id'], 'acadp_categories' );
        	$term_slug = $term->slug;		
		} elseif ( '' != $term_slug ) {
			$term = get_term_by( 'slug', $term_slug, 'acadp_categories' );
		}
		
		if ( '' != $term_slug ) {		
			$general_settings = get_option( 'acadp_general_settings' );
			$listings_settings = get_option( 'acadp_listings_settings' );
			$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
			
			$atts = shortcode_atts(array(
				'view'              => $listings_settings['default_view'],
				'featured'          => 1,
				'filterby'          => '',
				'orderby'           => $listings_settings['orderby'],
				'order'             => $listings_settings['order'],
				'listings_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
				'pagination'        => 1,
				'header'            => 1
			), $atts );
			
			$view = acadp_get_listings_current_view_name( $atts['view'] );
		
			// Enqueue style dependencies			
			wp_enqueue_style( ACADP_PLUGIN_NAME );

			if ( 'map' == $view ) {
				wp_enqueue_style( ACADP_PLUGIN_NAME . '-markerclusterer' );				
			}
		
			// Enqueue script dependencies			
			if ( 'map' == $view ) {
				wp_enqueue_script( ACADP_PLUGIN_NAME . '-markerclusterer' );
				wp_enqueue_script( ACADP_PLUGIN_NAME );
			}
		
			// ...				
			$can_show_header           = empty( $listings_settings['display_in_header'] ) ? 0 : (int) $atts['header'];
			$pre_content               = ! empty( $term ) && ! empty( $term->description ) ? nl2br( $term->description ) : '';
			$can_show_listings_count   = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
			$can_show_views_selector   = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
			$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
		
			$can_show_date          = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_user          = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_category      = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_views         = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_custom_fields = isset( $listings_settings['display_in_listing'] ) && in_array( 'custom_fields', $listings_settings['display_in_listing'] ) ? true : false;

			$can_show_images = empty( $general_settings['has_images'] ) ? false : true;
			
			$has_featured = apply_filters( 'acadp_has_featured', empty( $featured_listing_settings['enabled'] ) ? false : true );
			if ( $has_featured ) {
				$has_featured = $atts['featured'];
			}
				
			$current_order       = acadp_get_listings_current_order( $atts['orderby'] . '-' . $atts['order'] );
			$can_show_pagination = (int) $atts['pagination'];
			
			$has_price = empty( $general_settings['has_price'] ) ? false : true;
			$can_show_price = false;
			
			if ( $has_price ) {
				$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
			}
			
			$has_location = empty( $general_settings['has_location'] ) ? false : true;
			$can_show_location = false;
			
			if ( $has_location ) {
				$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
			}
			
			$span = 12;
			if ( $can_show_images ) $span = $span - 2;
			if ( $can_show_price ) $span = $span - 3;
			$span_middle = 'col-md-'.$span;

			// Define the query
			$paged = acadp_get_page_number();
			
			$args = array(				
				'post_type'      => 'acadp_listings',
				'post_status'    => 'publish',
				'posts_per_page' => (int) $atts['listings_per_page'],
				'paged'          => $paged,
	  		);
			
			$tax_queries = array();
			
			$tax_queries[] = array(
				'taxonomy'         => 'acadp_categories',
				'field'            => 'slug',
				'terms'            => $term_slug,
				'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_categories', $listings_settings['include_results_from'] ) ? true : false,
			);
			
			if ( $has_location && $general_settings['base_location'] > 0 ) {			
				$tax_queries[] = array(
					'taxonomy'         => 'acadp_locations',
					'field'            => 'term_id',
					'terms'            => $general_settings['base_location'],
					'include_children' => true,
				);				
			}
			
			$args['tax_query'] = ( count( $tax_queries ) > 1 ) ? array_merge( array( 'relation' => 'AND' ), $tax_queries ) : $tax_queries;
			
			$meta_queries = array();
			
			if ( 'map' == $view ) {
				$meta_queries['hide_map'] = array(
					'key'     => 'hide_map',
					'value'   => 0,
					'compare' => '='
				);
			}
			
			if ( $has_featured ) {			
				if ( 'featured' == $atts['filterby'] ) {
					$meta_queries['featured'] = array(
						'key'     => 'featured',
						'value'   => 1,
						'compare' => '='
					);
				} else {
					$meta_queries['featured'] = array(
						'key'     => 'featured',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);
				}				
			}
			
			switch ( $current_order ) {
				case 'title-asc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'title'          => 'ASC',
						);
					} else {
						$args['orderby'] = 'title';
						$args['order']   = 'ASC';
					};
					break;
				case 'title-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'title'          => 'DESC',
						);
					} else {
						$args['orderby'] = 'title';
						$args['order']   = 'DESC';
					};
					break;
				case 'date-asc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'date'           => 'ASC',
						);
					} else {
						$args['orderby'] = 'date';
						$args['order']   = 'ASC';
					};
					break;
				case 'date-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'date'           => 'DESC',
						);
					} else {
						$args['orderby'] = 'date';
						$args['order']   = 'DESC';
					};
					break;
				case 'price-asc' :
					if ( $has_featured ) {
						$meta_queries['price'] = array(
							'key'     => 'price',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'price'    => 'ASC',
						);
					} else {
						$args['meta_key'] = 'price';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'ASC';
					};
					break;
				case 'price-desc' :
					if ( $has_featured ) {
						$meta_queries['price'] = array(
							'key'     => 'price',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'price'    => 'DESC',
						);
					} else {
						$args['meta_key'] = 'price';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'DESC';
					};
					break;
				case 'views-asc' :
					if ( $has_featured ) {
						$meta_queries['views'] = array(
							'key'     => 'views',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'views'    => 'ASC',
						);
					} else {
						$args['meta_key'] = 'views';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'ASC';
					};
					break;
				case 'views-desc' :
					if ( $has_featured ) {
						$meta_queries['views'] = array(
							'key'     => 'views',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'views'    => 'DESC',
						);
					} else {
						$args['meta_key'] = 'views';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'DESC';
					};
					break;
				case 'rand-asc' :
				case 'rand-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = 'meta_value_num rand';
					} else {
						$args['orderby'] = 'rand';
					};
					break;
			}
			
			$count_meta_queries = count( $meta_queries );
			if ( $count_meta_queries ) {
				$args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : $meta_queries;
			}
		
			$args = apply_filters( 'acadp_query_args', $args, $shortcode );
			$acadp_query = new WP_Query( $args );
			
			// Start the Loop
			global $post;
			
			// Process output
			if ( $acadp_query->have_posts() ) {			
				ob_start();
				include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
				return ob_get_clean();				
			} elseif ( ! empty( $pre_content ) ) {			
				return '<span>' . $pre_content . '</span>';				
			}		
		}
		
		return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-categories.php

Advanced Classifieds & Directory Pro [acadp_listings] Shortcode

The Advanced Classifieds and Directory Pro shortcode is designed to list classified ads on a WordPress page. It fetches and displays listings from the database with an array of customizable attributes. This shortcode allows you to filter and sort listings, customize the number of listings per page, and display additional elements like headers and pagination. It also enables views in different formats, handles script dependencies, and defines queries based on user-defined parameters. It’s particularly useful for creating dynamic, user-friendly classified ad pages on your WordPress site.

Shortcode: [acadp_listings]

Parameters

Here is a list of all possible acadp_listings shortcode parameters and attributes:

  • view – Defines the layout of the listings
  • location – Filters listings by location
  • category – Filters listings by category
  • featured – Determines if featured listings are shown
  • filterby – Allows filtering by custom parameters
  • custom_fields – Allows inclusion of custom fields in the listing
  • orderby – Sorts listings by a specific field
  • order – Specifies the sorting order (ascending or descending)
  • columns – Sets the number of columns in the listing layout
  • listings_per_page – Determines the number of listings per page
  • pagination – Enables or disables pagination
  • header – Enables or disables the listing header

Examples and Usage

Basic example – Displaying all listings with default settings

[acadp_listings]

Advanced examples

Displaying listings in a specific category and location, ordered by date in descending order, and with pagination disabled.

[acadp_listings category=3 location=2 orderby='date' order='desc' pagination=0]

Displaying featured listings only, in a grid view, with a specific number of listings per page and without the header.

[acadp_listings view='grid' featured=1 listings_per_page=10 header=0]

Displaying listings with custom fields, sorted by price in ascending order, and with the number of columns set to 4.

[acadp_listings custom_fields='field1,field2' orderby='price' order='asc' columns=4]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_listings] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_listings", array( $this, "run_shortcode_listings" ) );

Shortcode PHP function:

                    function run_shortcode_listings( $atts ) {	
		$shortcode = 'acadp_listings';
		
		$general_settings = get_option( 'acadp_general_settings' );
		$listings_settings = get_option( 'acadp_listings_settings' );
		$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
		
		$atts = shortcode_atts( array(
			'view'              => $listings_settings['default_view'],
			'location'          => 0,
			'category'          => 0,			
			'featured'          => 1,
			'filterby'          => '',
			'custom_fields'     => '',
			'orderby'           => $listings_settings['orderby'],
			'order'             => $listings_settings['order'],
			'columns'           => $listings_settings['columns'],
			'listings_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
			'pagination'        => 1,
			'header'            => 1
		), $atts );
		
		$view = acadp_get_listings_current_view_name( $atts['view'] );
			
		// Enqueue style dependencies		
		wp_enqueue_style( ACADP_PLUGIN_NAME );

		if ( 'map' == $view ) {
			wp_enqueue_style( ACADP_PLUGIN_NAME . '-markerclusterer' );				
		}
		
		// Enqueue script dependencies
		if ( 'map' == $view ) {
			wp_enqueue_script( ACADP_PLUGIN_NAME . '-markerclusterer' );
			wp_enqueue_script( ACADP_PLUGIN_NAME );
		}

		// ...
		$listings_settings['columns'] = (int) $atts['columns'];

		$can_show_header           = empty( $listings_settings['display_in_header'] ) ? 0 : (int) $atts['header'];
		$pre_content               = '';
		$can_show_listings_count   = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
		$can_show_views_selector   = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
		$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
		
		$can_show_date          = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_user          = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_category      = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_views         = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_custom_fields = isset( $listings_settings['display_in_listing'] ) && in_array( 'custom_fields', $listings_settings['display_in_listing'] ) ? true : false;

		$can_show_images = empty( $general_settings['has_images'] ) ? false : true;
		
		$has_featured = apply_filters( 'acadp_has_featured', empty( $featured_listing_settings['enabled'] ) ? false : true );
		if ( $has_featured ) {
			$has_featured = $atts['featured'];
		}		
			
		$current_order       = acadp_get_listings_current_order( $atts['orderby'] . '-' . $atts['order'] );
		$can_show_pagination = (int) $atts['pagination'];
			
		$has_price = empty( $general_settings['has_price'] ) ? false : true;
		$can_show_price = false;
		
		if ( $has_price ) {
			$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
		}
			
		$has_location = empty( $general_settings['has_location'] ) ? false : true;
		$can_show_location = false;
		
		if ( $has_location ) {
			$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
		}
			
		$span = 12;
		if ( $can_show_images ) $span = $span - 2;
		if ( $can_show_price ) $span = $span - 3;
		$span_middle = 'col-md-' . $span;

		// Define the query
		$paged = acadp_get_page_number();
			
		$args = array(				
			'post_type'      => 'acadp_listings',
			'post_status'    => 'publish',
			'posts_per_page' => (int) $atts['listings_per_page'],
			'paged'          => $paged,
	  	);
			
		$tax_queries = array();
		
		if ( ! empty( $atts['category'] ) ) {		
			$tax_queries[] = array(
				'taxonomy'         => 'acadp_categories',
				'field'            => 'term_id',
				'terms'            => array_map( 'intval', explode( ',', $atts['category'] ) ),
				'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_categories', $listings_settings['include_results_from'] ) ? true : false,
			);			
		}
		
		if ( $has_location ) {		
			if ( ! empty( $atts['location'] ) ) {			
				$tax_queries[] = array(
					'taxonomy'         => 'acadp_locations',
					'field'            => 'term_id',
					'terms'            => array_map( 'intval', explode( ',', $atts['location'] ) ),
					'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_locations', $listings_settings['include_results_from'] ) ? true : false,
				);				
			} elseif ( $general_settings['base_location'] > 0 ) {			
				$tax_queries[] = array(
					'taxonomy'         => 'acadp_locations',
					'field'            => 'term_id',
					'terms'            => $general_settings['base_location'],
					'include_children' => true,
				);			
			}				
		}
		
		$args['tax_query'] = ( count( $tax_queries ) > 1 ) ? array_merge( array( 'relation' => 'AND' ), $tax_queries ) : $tax_queries;
			
		$meta_queries = array();
		
		if ( 'map' == $view ) {
			$meta_queries['hide_map'] = array(
				'key'     => 'hide_map',
				'value'   => 0,
				'compare' => '='
			);
		}
		
		if ( $has_featured ) {			
			if ( 'featured' == $atts['filterby'] ) {
				$meta_queries['featured'] = array(
					'key'     => 'featured',
					'value'   => 1,
					'compare' => '='
				);
			} else {
				$meta_queries['featured'] = array(
					'key'     => 'featured',
					'type'    => 'NUMERIC',
					'compare' => 'EXISTS',
				);
			}			
		}

		if ( ! empty( $atts['custom_fields'] ) ) {
			$fields = explode( ',', $atts['custom_fields'] );
			$cf = array();

			foreach ( $fields as $field ) {
				if ( strpos( $field, ':' ) !== false ) {
					$field_meta = explode( ':', $field );
					$field_meta = array_map( 'trim', $field_meta );

					if ( 2 == count( $field_meta ) ) {
						$key = (int) $field_meta[0];
						
						if ( strpos( $field_meta[1], '|' ) !== false ) {
							$values = explode( '|', $field_meta[1] );
							$values = array_map( 'trim', $values );
						} else {
							$values = trim( $field_meta[1] );
						}

						$cf[ $key ] = $values;
					}
				}
			}

			foreach ( $cf as $key => $values ) {
				$key = sanitize_key( $key );

				if ( is_array( $values ) ) {				
					if ( count( $values ) > 1 ) {					
						$sub_meta_queries = array();
						
						foreach ( $values as $value ) {
							$sub_meta_queries[] = array(
								'key'		=> $key,
								'value'		=> sanitize_text_field( $value ),
								'compare'	=> 'LIKE'
							);
						}
						
						$meta_queries[] = array_merge( array( 'relation' => 'OR' ), $sub_meta_queries );					
					} else {					
						$meta_queries[] = array(
							'key'		=> $key,
							'value'		=> sanitize_text_field( $values[0] ),
							'compare'	=> 'LIKE'
						);					
					}						
				} else {					
					$field_type = get_post_meta( $key, 'type', true );					
					$operator = ( 'text' == $field_type || 'textarea' == $field_type || 'url' == $field_type ) ? 'LIKE' : '=';
					
					$meta_queries[] = array(
						'key'		=> $key,
						'value'		=> sanitize_text_field( $values ),
						'compare'	=> $operator
					);					
				}				
			}
		}
		
		switch ( $current_order ) {
			case 'title-asc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'title'          => 'ASC',
					);
				} else {
					$args['orderby'] = 'title';
					$args['order']   = 'ASC';
				};
				break;
			case 'title-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'title'          => 'DESC',
					);
				} else {
					$args['orderby'] = 'title';
					$args['order']   = 'DESC';
				};
				break;
			case 'date-asc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'date'           => 'ASC',
					);
				} else {
					$args['orderby'] = 'date';
					$args['order']   = 'ASC';
				};
				break;
			case 'date-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'date'           => 'DESC',
					);
				} else {
					$args['orderby'] = 'date';
					$args['order']   = 'DESC';
				};
				break;
			case 'price-asc' :
				if ( $has_featured ) {
					$meta_queries['price'] = array(
						'key'     => 'price',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'price'    => 'ASC',
					);
				} else {
					$args['meta_key'] = 'price';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'ASC';
				};
				break;
			case 'price-desc' :
				if ( $has_featured ) {
					$meta_queries['price'] = array(
						'key'     => 'price',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'price'    => 'DESC',
					);
				} else {
					$args['meta_key'] = 'price';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'DESC';
				};
				break;
			case 'views-asc' :
				if ( $has_featured ) {
					$meta_queries['views'] = array(
						'key'     => 'views',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'views'    => 'ASC',
					);
				} else {
					$args['meta_key'] = 'views';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'ASC';
				};
				break;
			case 'views-desc' :
				if ( $has_featured ) {
					$meta_queries['views'] = array(
						'key'     => 'views',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'views'    => 'DESC',
					);
				} else {
					$args['meta_key'] = 'views';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'DESC';
				};
				break;
			case 'rand-asc' :
			case 'rand-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = 'meta_value_num rand';
				} else {
					$args['orderby'] = 'rand';
				};
				break;
		}
			
		$count_meta_queries = count( $meta_queries );
		if ( $count_meta_queries ) {
			$args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : $meta_queries;
		}
		
		$args = apply_filters( 'acadp_query_args', $args, $shortcode );
		$acadp_query = new WP_Query( $args );
			
		// Start the Loop
		global $post;
			
		// Process output
		if ( $acadp_query->have_posts() ) {			
			ob_start();
			include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
			return ob_get_clean();				
		}
		
		return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-listings.php

Advanced Classifieds & Directory Pro [acadp_locations] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is designed to display locations. It fetches location data based on the plugin’s general, listings, and location settings. The shortcode enqueues style dependencies, sets attributes like parent, columns, depth, order, and count, and retrieves terms from the ‘acadp_locations’ taxonomy. If terms exist, it includes a template for public location display. If not, it returns ‘No results found’.

Shortcode: [acadp_locations]

Parameters

Here is a list of all possible acadp_locations shortcode parameters and attributes:

  • parent – Defines the base location for listing.
  • columns – Specifies the number of columns in the layout.
  • depth – Determines the depth of location hierarchy.
  • orderby – Sets the sorting order of locations.
  • order – Arranges locations in ascending or descending order.
  • show_count – Displays the count of listings for each location.
  • pad_counts – Includes listings from child locations in count.
  • hide_empty – Hides locations with no associated listings.

Examples and Usage

Basic example – Displaying the default locations using the ACADP locations shortcode

[acadp_locations /]

Advanced examples

Displaying the locations in a specific order. The following shortcode will display the locations in ascending order based on their names.

[acadp_locations orderby="name" order="ASC" /]

Displaying the locations with specific columns and depth. The following shortcode will display the locations with 3 columns and a depth of 2.

[acadp_locations columns="3" depth="2" /]

Displaying the locations while hiding the empty ones. The following shortcode will display the locations and hide the ones that do not have any listings associated with them.

[acadp_locations hide_empty="1" /]

Displaying the locations while showing the count of listings. The following shortcode will display the locations along with the count of listings associated with each location.

[acadp_locations show_count="1" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_locations] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_locations", array( $this, "run_shortcode_locations" ) );

Shortcode PHP function:

                    function run_shortcode_locations( $atts ) {	
		$shortcode = 'acadp_locations';
		
		$general_settings   = get_option( 'acadp_general_settings' );
		$listings_settings  = get_option( 'acadp_listings_settings' );
		$locations_settings = get_option( 'acadp_locations_settings' );		
		$has_location       = empty( $general_settings['has_location'] ) ? false : true;
		
		if ( $has_location ) {		
			// Enqueue style dependencies
			wp_enqueue_style( ACADP_PLUGIN_NAME );
			
			// ...		
			$attributes = shortcode_atts( 
				array(
					'parent'     => max( 0, $general_settings['base_location'] ),
					'columns'    => $locations_settings['columns'],
					'depth'      => $locations_settings['depth'],
					'orderby'    => $locations_settings['orderby'], 
					'order'      => $locations_settings['order'],					
					'show_count' => ! empty( $locations_settings['show_count'] ) ? 1 : 0,
					'pad_counts' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_locations', $listings_settings['include_results_from'] ) ? true : false,
					'hide_empty' => ! empty( $locations_settings['hide_empty'] ) ? 1 : 0
				),
				$atts
  			);
		
			$terms = get_terms( 
				'acadp_locations',
				array(
					'parent'       => (int) $attributes['parent'],
					'orderby'      => sanitize_text_field( $attributes['orderby'] ), 
					'order'        => sanitize_text_field( $attributes['order'] ),
					'hide_empty'   => ! empty( $attributes['hide_empty'] ) ? 1 : 0,				
					'hierarchical' => ! empty( $attributes['hide_empty'] ) ? true : false,
				)
			);
			 
			if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {	
				// Backward compatibility (version < 1.7.3)	
				$locations_settings = $attributes;

				ob_start();
				include( acadp_get_template( "locations/acadp-public-locations-display.php" ) );
				return ob_get_clean();			
			}		
		}
		
		return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-locations.php

Advanced Classifieds & Directory Pro [acadp_location] Shortcode

The Advanced Classifieds and Directory Pro shortcode is designed to display listings based on location. It retrieves general settings, checks if location is enabled, and gets the term slug and term. It determines the listings settings, featured listing settings, and sets the attributes for the listing view. It also enqueues style and script dependencies based on the current view. The shortcode then sets variables for showing various elements in the header and listing, such as date, user, category, views, custom fields, images, and location. Finally, it defines the query for listings, applies filters, and initiates a new WP_Query. The output is processed and returned. If no results are found, a ‘No results found’ message is displayed.

Shortcode: [acadp_location]

Parameters

Here is a list of all possible acadp_location shortcode parameters and attributes:

  • view – defines the display style of the listings
  • featured – toggles the display of featured listings
  • filterby – sets the filter criteria for the listings
  • orderby – determines the sort order of the listings
  • order – sets the direction of the sort order
  • listings_per_page – sets the number of listings to display per page
  • pagination – enables or disables pagination
  • header – enables or disables the display of the header
  • id – specifies the location by its unique identifier

Examples and Usage

Basic example – Displaying the location-specific listings using the shortcode by referencing the ID of the location.

[acadp_location id=1 /]

Advanced examples

Displaying the location-specific listings with a defined view, order, and listings per page. The listings will be displayed in a grid view, ordered by title in ascending order, and showing 10 listings per page.

[acadp_location id=1 view="grid" orderby="title" order="asc" listings_per_page=10 /]

Using the shortcode to display the location-specific listings with featured listings only. The shortcode will display only the listings that are marked as featured.

[acadp_location id=1 featured=1 /]

Using the shortcode to display the location-specific listings with a custom header. The shortcode will display listings with a custom header.

[acadp_location id=1 header="Custom Header" /]

Using the shortcode to display the location-specific listings with pagination. The shortcode will display listings with pagination enabled.

[acadp_location id=1 pagination=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_location] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_location", array( $this, "run_shortcode_location" ) );

Shortcode PHP function:

                    function run_shortcode_location( $atts ) {	
		$shortcode = 'acadp_location';
		
		$general_settings = get_option( 'acadp_general_settings' );
		$has_location = empty( $general_settings['has_location'] ) ? false : true;
		$term_slug = '';
		$term = '';
		
		if ( $has_location ) {
			$term_slug = get_query_var( 'acadp_location' );
			if ( '' == $term_slug && ! empty( $atts['id'] ) ) {		
				$term = get_term_by( 'id', (int) $atts['id'], 'acadp_locations' );
        		$term_slug = $term->slug;		
			} elseif ( '' != $term_slug ) {
				$term = get_term_by( 'slug', $term_slug, 'acadp_locations' );
			}
		}
		
		if ( '' != $term_slug ) {			
			$listings_settings = get_option( 'acadp_listings_settings' );
			$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
			
			$atts = shortcode_atts( array(
				'view'              => $listings_settings['default_view'],
				'featured'          => 1,
				'filterby'          => '',
				'orderby'           => $listings_settings['orderby'],
				'order'             => $listings_settings['order'],
				'listings_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
				'pagination'        => 1,
				'header'            => 1
			), $atts );
			
			$view = acadp_get_listings_current_view_name( $atts['view'] );
			
			// Enqueue style dependencies			
			wp_enqueue_style( ACADP_PLUGIN_NAME );

			if ( 'map' == $view ) {
				wp_enqueue_style( ACADP_PLUGIN_NAME . '-markerclusterer' );				
			}
		
			// Enqueue script dependencies
			if ( 'map' == $view ) {
				wp_enqueue_script( ACADP_PLUGIN_NAME . '-markerclusterer' );
				wp_enqueue_script( ACADP_PLUGIN_NAME );
			}			
		
			// ...
			$can_show_header           = empty( $listings_settings['display_in_header'] ) ? 0 : (int) $atts['header'];
			$pre_content               = ! empty( $term ) && ! empty( $term->description ) ? nl2br( $term->description ) : '';
			$can_show_listings_count   = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
			$can_show_views_selector   = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
			$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
		
			$can_show_date          = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_user          = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_category      = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_views         = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_custom_fields = isset( $listings_settings['display_in_listing'] ) && in_array( 'custom_fields', $listings_settings['display_in_listing'] ) ? true : false;

			$can_show_images = empty( $general_settings['has_images'] ) ? false : true;
			
			$has_featured = apply_filters( 'acadp_has_featured', empty( $featured_listing_settings['enabled'] ) ? false : true );
			if ( $has_featured ) {
				$has_featured = $atts['featured'];
			}
			
			$current_order       = acadp_get_listings_current_order( $atts['orderby'] . '-' . $atts['order'] );
			$can_show_pagination = (int) $atts['pagination'];
			
			$has_price = empty( $general_settings['has_price'] ) ? false : true;
			$can_show_price = false;
		
			if ( $has_price ) {
				$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
			}			
			
			$can_show_location = false;		
			if ( $has_location ) {
				$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
			}
		
			$span = 12;
			if ( $can_show_images ) $span = $span - 2;
			if ( $can_show_price ) $span = $span - 3;
			$span_middle = 'col-md-' . $span;

			// Define the query
			$paged = acadp_get_page_number();
			
			$args = array(				
				'post_type'      => 'acadp_listings',
				'post_status'    => 'publish',
				'posts_per_page' => (int) $atts['listings_per_page'],
				'paged'          => $paged,		
	  		);
			
			if ( $has_location ) {		
				$args['tax_query'] = array(
					array(
						'taxonomy'         => 'acadp_locations',
						'field'            => 'slug',
						'terms'            => $term_slug,
						'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_locations', $listings_settings['include_results_from'] ) ? true : false,
					),
				);				
			}
			
			$meta_queries = array();
			
			if ( 'map' == $view ) {
				$meta_queries['hide_map'] = array(
					'key'     => 'hide_map',
					'value'   => 0,
					'compare' => '='
				);
			}
			
			if ( $has_featured ) {			
				if ( 'featured' == $atts['filterby'] ) {
					$meta_queries['featured'] = array(
						'key'     => 'featured',
						'value'   => 1,
						'compare' => '='
					);
				} else {
					$meta_queries['featured'] = array(
						'key'     => 'featured',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);
				}				
			}
			
			switch ( $current_order ) {
				case 'title-asc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'title'          => 'ASC',
						);
					} else {
						$args['orderby'] = 'title';
						$args['order']   = 'ASC';
					};
					break;
				case 'title-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'title'          => 'DESC',
						);
					} else {
						$args['orderby'] = 'title';
						$args['order']   = 'DESC';
					};
					break;
				case 'date-asc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'date'           => 'ASC',
						);
					} else {
						$args['orderby'] = 'date';
						$args['order']   = 'ASC';
					};
					break;
				case 'date-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'date'           => 'DESC',
						);
					} else {
						$args['orderby'] = 'date';
						$args['order']   = 'DESC';
					};
					break;
				case 'price-asc' :
					if ( $has_featured ) {
						$meta_queries['price'] = array(
							'key'     => 'price',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'price'    => 'ASC',
						);
					} else {
						$args['meta_key'] = 'price';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'ASC';
					};
					break;
				case 'price-desc' :
					if ( $has_featured ) {
						$meta_queries['price'] = array(
							'key'     => 'price',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'price'    => 'DESC',
						);
					} else {
						$args['meta_key'] = 'price';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'DESC';
					};
					break;
				case 'views-asc' :
					if ( $has_featured ) {
						$meta_queries['views'] = array(
							'key'     => 'views',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'views'    => 'ASC',
						);
					} else {
						$args['meta_key'] = 'views';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'ASC';
					};
					break;
				case 'views-desc' :
					if ( $has_featured ) {
						$meta_queries['views'] = array(
							'key'     => 'views',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'views'    => 'DESC',
						);
					} else {
						$args['meta_key'] = 'views';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'DESC';
					};
					break;
				case 'rand-asc' :
				case 'rand-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = 'meta_value_num rand';
					} else {
						$args['orderby'] = 'rand';
					};
					break;
			}

			$count_meta_queries = count( $meta_queries );
			if ( $count_meta_queries ) {
				$args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : $meta_queries;
			}
		
			$args = apply_filters( 'acadp_query_args', $args, $shortcode );
			$acadp_query = new WP_Query( $args );
			
			// Start the Loop
			global $post;
			
			// Process output
			if ( $acadp_query->have_posts() ) {
				ob_start();
				include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
				return ob_get_clean();			
			} elseif ( ! empty( $pre_content ) ) {			
				return '<span>' . $pre_content . '</span>';				
			}		
		}
		
		return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-locations.php

Advanced Classifieds & Directory Pro [acadp_checkout] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode, “acadp_checkout”, allows users to checkout their listings. If the user is not logged in, it returns a login form. Once logged in, it checks if the post ID is a valid ACADP listing. If the request method is POST and the nonce is verified, it places the order. Otherwise, it displays the checkout form with options for featured listings, if enabled. It also enqueues necessary styles and scripts, and provides hooks for developers. If something goes wrong, a message is displayed.

Shortcode: [acadp_checkout]

Examples and Usage

Basic example – The basic usage of the “acadp_checkout” shortcode. This shortcode doesn’t require any parameters and will display the checkout form for the current listing if the user is logged in.

[acadp_checkout /]

Advanced examples

While the “acadp_checkout” shortcode doesn’t have any parameters, it can be used in conjunction with other shortcodes to create more complex functionality. For example, you can use it with the “acadp_listing” shortcode to display the checkout form for a specific listing.

[acadp_listing id=123]
[acadp_checkout /]

In this example, the “acadp_listing” shortcode is used to set the current listing to the listing with the ID of 123. Then, the “acadp_checkout” shortcode is used to display the checkout form for that listing.

Another example is to use it with the “acadp_login_form” shortcode to display a login form if the user is not logged in.

[acadp_login_form]
[acadp_checkout /]

In this example, the “acadp_login_form” shortcode is used to display a login form if the user is not logged in. If the user is logged in, the “acadp_checkout” shortcode is used to display the checkout form for the current listing.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_checkout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_checkout", array( $this, "run_shortcode_checkout" ) );

Shortcode PHP function:

                    function run_shortcode_checkout() {	
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();		
		}
		
		$shortcode = 'acadp_checkout';
		
		$post_id = get_query_var( 'acadp_listing' );
		
		if ( ! empty( $post_id ) && 'acadp_listings' == get_post_type( $post_id ) ) {			
			if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['acadp_checkout_nonce'] ) && wp_verify_nonce( $_POST['acadp_checkout_nonce'], 'acadp_process_payment' ) ) {									
				$this->place_order();				
			} else {	
				$options = apply_filters( 'acadp_checkout_form_data', array(), $post_id );
				
				$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
				if ( ! empty( $featured_listing_settings['enabled'] ) ) {
					$options[] = array(
						'type'  => 'header',
						'label' => $featured_listing_settings['label']
					);
					
					$options[] = array( 
						'type'        => 'checkbox',
						'name'        => 'featured',
						'value'       => 1,
						'selected'    => 1,
						'description' => $featured_listing_settings['description'],
						'price'       => $featured_listing_settings['price']
					);
				}
				
				// Enqueue style dependencies
				wp_enqueue_style( ACADP_PLUGIN_NAME );
		
				// Enqueue script dependencies
				wp_enqueue_script( ACADP_PLUGIN_NAME );
				
				// Hook for developers
				do_action( 'acadp_before_checkout_form' );
			
				// ...	
				ob_start();
				include( acadp_get_template( "payments/acadp-public-checkout-display.php" ) );
				return ob_get_clean();			
			}			
		} else {		
			return '<span>' . __( 'Sorry, something went wrong.', 'advanced-classifieds-and-directory-pro' ) . '</span>';			
		}	
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-payments.php

Advanced Classifieds & Directory Pro [acadp_payment_errors] Shortcode

The Advanced Classifieds and Directory Pro plugin shortcode, acadp_payment_errors, is designed to handle payment errors. This shortcode retrieves any payment errors associated with a specific order ID. If an error is identified, it is stored in the content and the error transient is deleted. This ensures the error is handled and removed promptly.

Shortcode: [acadp_payment_errors]

Examples and Usage

Basic example – The shortcode can be used to display any payment errors related to a specific order. By simply placing this shortcode, you can display the error message of an order in the front-end.

[acadp_payment_errors]

Advanced examples

Although the “acadp_payment_errors” shortcode does not accept any parameters directly, its behavior can be influenced by the ‘acadp_order’ query variable. This variable can be set via the URL or by using the ‘set_query_var’ function.


// Set the 'acadp_order' query variable to the order ID
set_query_var( 'acadp_order', $order_id );

// Now use the shortcode
echo do_shortcode( '[acadp_payment_errors]' );

This way, you can display the payment errors of a specific order programmatically. Remember to replace $order_id with the ID of the order you want to check.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_payment_errors] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_payment_errors", array( $this, "run_shortcode_payment_errors" ) );

Shortcode PHP function:

                    function run_shortcode_payment_errors( $atts, $content = '' ) {	
		if ( $order_id = get_query_var('acadp_order') ) {
			if ( $error = get_transient( "acadp_payment_errors_{$order_id}" ) ) {
				$content = $error;
    			delete_transient( "acadp_payment_errors_{$order_id}" );
			}			
		}
		
		return $content;	
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-payments.php

Advanced Classifieds & Directory Pro [acadp_payment_receipt] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is used to display a payment receipt. This shortcode is activated when a user is logged in and an order is placed. The shortcode fetches the order details, checks if the featured listing is enabled, and then displays the payment receipt. If an error occurs, it returns a failure message.

Shortcode: [acadp_payment_receipt]

Examples and Usage

Basic Example – The following shortcode is a simple usage of the ‘acadp_payment_receipt’ shortcode. It does not require any additional parameters as it fetches the order details from the current user session.

[acadp_payment_receipt]

Advanced Examples

1. Displaying the payment receipt of a specific order by passing the order id as a parameter. This shortcode will fetch and display the details of the order with the id provided.

[acadp_payment_receipt order_id=123]

2. Displaying the payment receipt with additional information. This example includes two parameters, ‘order_id’ and ‘featured’. When ‘featured’ is set to true, it includes the featured listing settings in the order details.

[acadp_payment_receipt order_id=123 featured=true]
Please note that these examples are hypothetical and might not work without proper modifications to the ‘run_shortcode_payment_receipt’ function to accept and process these parameters.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_payment_receipt] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_payment_receipt", array( $this, "run_shortcode_payment_receipt" ) );

Shortcode PHP function:

                    function run_shortcode_payment_receipt() {	
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}
		
		$shortcode = 'acadp_payment_receipt';
		
		if ( $order_id = get_query_var('acadp_order') ) {
			$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
			
			// Enqueue style dependencies
			wp_enqueue_style( ACADP_PLUGIN_NAME );
			
			// ...
			$order = get_post( $order_id );
			$post_meta = get_post_meta( $order_id );
			
			$order_details = apply_filters( 'acadp_order_details', array(), $order_id );

			if ( ! empty( $featured_listing_settings['enabled'] ) && isset( $post_meta['featured'] ) ) {
				$order_details[] = $featured_listing_settings;
			}
			
			ob_start();
			include( acadp_get_template( "payments/acadp-public-payment-receipt-display.php" ) );
			return ob_get_clean();		
		} else {		
			return '<span>' . __( 'Sorry, something went wrong.', 'advanced-classifieds-and-directory-pro' ) . '</span>';			
		}	
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-payments.php

Advanced Classifieds & Directory Pro [acadp_payment_history] Shortcode

The Advanced Classifieds and Directory Pro shortcode, acadp_payment_history, generates a user’s payment history. This shortcode checks if a user is logged in and has the necessary permissions. If not, it displays appropriate error messages. If the user is authorized, it queries the ‘acadp_payments’ post type, displaying the current user’s payment history. It returns a list of payments or a ‘No results found’ message if no payments exist.

Shortcode: [acadp_payment_history]

Examples and Usage

Basic example – Displays the payment history for the current user

[acadp_payment_history]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_payment_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_payment_history", array( $this, "run_shortcode_payment_history" ) );

Shortcode PHP function:

                    function run_shortcode_payment_history() {	
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}
		
		if ( ! acadp_current_user_can('edit_acadp_listings') ) {
			return '<span>' . __( 'You do not have sufficient permissions to access this page.', 'advanced-classifieds-and-directory-pro' ) . '</span>';
		}
		
		$shortcode = 'acadp_payment_history';
		
		$listings_settings = get_option( 'acadp_listings_settings' );

		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );

		// Define the query
		$paged = acadp_get_page_number();
			
		$args = array(				
			'post_type'      => 'acadp_payments',
			'posts_per_page' => isset( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : 10,
			'paged'          => $paged,
			'author'         => get_current_user_id(),
	  	);
			
		$acadp_query = new WP_Query( $args );
		
		// Start the Loop
		global $post;
			
		// Process output
		if ( $acadp_query->have_posts() ) {		
			ob_start();
			include( acadp_get_template( "payments/acadp-public-payment-history-display.php" ) );
			wp_reset_postdata(); // Use reset postdata to restore orginal query
			return ob_get_clean();		
		} else {		
			return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
		}			
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-payments.php

Advanced Classifieds & Directory Pro [acadp_login] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode ‘acadp_login’ is responsible for rendering the login form. It enqueues style and script dependencies, handles redirects, and displays error messages. This shortcode checks if the user is logged in, if so, it returns the ‘acadp_logout’ shortcode. It also processes various user states such as recently logged out, newly registered, or password updated. It provides forgot password and registration URLs.

Shortcode: [acadp_login]

Examples and Usage

Basic example – Display a login form with the default settings.

[acadp_login /]

Advanced examples

Display a login form with a specific redirect URL. After logging in, the user will be redirected to the specified URL.

[acadp_login redirect="http://yourwebsite.com/your-page/" /]

Display a login form with multiple parameters. This example includes a redirect URL and an error message for an invalid username.

[acadp_login redirect="http://yourwebsite.com/your-page/" login="invalid_username" /]

It’s important to note that the ‘login’ parameter in the shortcode should match the error codes used in the plugin’s code. In this case, ‘invalid_username’ is an error code defined in the plugin.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acadp_login', array( $this, 'render_login_form' ) );

Shortcode PHP function:

                    function render_login_form( $attributes, $content = null ) {	
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// Enqueue script dependencies		
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-validator' );		
		wp_enqueue_script( ACADP_PLUGIN_NAME );
		
		if ( is_user_logged_in() ) {
			return do_shortcode( '[acadp_logout]' );
		}
		
		// Parse shortcode attributes
		$default_attributes = array( 'redirect' => '' );
		$attributes = shortcode_atts( $default_attributes, $attributes );

		// Pass the redirect parameter to the WordPress login functionality: by default,
		// don't specify a redirect, but if a valid redirect URL has been passed as
		// request parameter, use it.
		if ( isset( $_REQUEST['redirect_to'] ) ) {
			$attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], $attributes['redirect'] );
		}

		// Error messages
		$errors = array();
		if ( isset( $_REQUEST['login'] ) ) {
			$error_codes = explode( ',', $_REQUEST['login'] );

			foreach ( $error_codes as $code ) {
				$code = sanitize_key( $code );
				
				if ( 'invalid_username' == $code ) $code = 'invalidcombo';
				$errors[] = $this->get_error_message( $code );
			}
		}
		$attributes['errors'] = $errors;

		// Check if user just logged out
		$attributes['logged_out'] = isset( $_REQUEST['logged_out'] ) && $_REQUEST['logged_out'] == true;

		// Check if the user just registered
		$attributes['registered'] = isset( $_REQUEST['registered'] );

		// Check if the user just requested a new password
		$attributes['lost_password_sent'] = isset( $_REQUEST['checkemail'] ) && $_REQUEST['checkemail'] == 'confirm';

		// Check if user just updated password
		$attributes['password_updated'] = isset( $_REQUEST['password'] ) && $_REQUEST['password'] == 'changed';
		
		// Forgot Password, Registration URLs
		$page_settings = get_option( 'acadp_page_settings' );
			
        $attributes['forgot_password_url'] = esc_url_raw( get_permalink( $page_settings['forgot_password'] ) );
		$attributes['register_url'] = esc_url_raw( get_permalink( $page_settings['register_form'] ) );
		
		if ( ! empty( $attributes['redirect'] ) ) {
			$attributes['forgot_password_url'] = add_query_arg( 'redirect_to', rawurlencode( $attributes['redirect'] ), $attributes['forgot_password_url'] );
			$attributes['register_url'] = add_query_arg( 'redirect_to', rawurlencode( $attributes['redirect'] ), $attributes['register_url'] );
		}

		// Render the login form using an external template
		return $this->get_template_html( 'login', $attributes );		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-registration.php

Advanced Classifieds & Directory Pro [acadp_logout] Shortcode

The Advanced Classifieds and Directory Pro shortcode, ‘acadp_logout’, initiates a function to render a logout button. It enables users to log out swiftly from the site.

Shortcode: [acadp_logout]

Examples and Usage

Basic example – The following shortcode is a simple usage of the ‘acadp_logout’ shortcode that will render a logout button without any additional parameters.

[acadp_logout /]

Advanced examples

Below is an advanced usage of the ‘acadp_logout’ shortcode. In this example, we are adding extra parameters to the shortcode. However, it’s important to note that the ‘acadp_logout’ shortcode does not accept any parameters in its current form. This is just an illustrative example of how one might add parameters to a shortcode.

[acadp_logout id="1" class="my-logout-button" /]

In this example, the ‘id’ parameter is used to assign a unique ID to the logout button, while the ‘class’ parameter is used to assign a CSS class to the button. This would allow for easy styling of the button using CSS.

However, to make these parameters functional, the ‘render_logout_button’ function would need to be modified to accept and use these parameters. Here’s an example of how you might modify the function:

function render_logout_button( $attributes, $content = null ) {
    $attributes = shortcode_atts( array(
        'id' => '',
        'class' => '',
    ), $attributes );

    return $this->get_template_html( 'logout', $attributes );
}

This modified function now accepts ‘id’ and ‘class’ parameters, which can be used in the ‘logout’ template to style the logout button.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_logout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acadp_logout', array( $this, 'render_logout_button' ) );

Shortcode PHP function:

                    function render_logout_button( $attributes, $content = null ) {	
		return $this->get_template_html( 'logout', $attributes );	
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-registration.php

Advanced Classifieds & Directory Pro [acadp_register] Shortcode

The Advanced Classifieds and Directory Pro shortcode ‘acadp_register’ is designed to render a user registration form. This shortcode checks if a user is already logged in or if new user registration is currently allowed. It enqueues style and script dependencies, such as the plugin’s validator and reCaptcha if necessary. The shortcode also parses attributes, validates redirect URLs, and retrieves possible errors from request parameters. It then returns the registration form template.

Shortcode: [acadp_register]

Examples and Usage

Basic example – The shortcode [acadp_register] can be used to display the registration form on any page or post. This is a simple and efficient way of allowing users to register on your website.

[acadp_register /]

Advanced examples

Using the shortcode to display the registration form with a custom redirect URL. After successful registration, the user will be redirected to the specified URL.

[acadp_register redirect="https://yourwebsite.com/welcome-page" /]

Using the shortcode to display the registration form with error handling. If there are any errors during the registration process, they will be displayed to the user. This is useful for debugging and user experience improvements.

[acadp_register errors="true" /]
Please note that the “errors” attribute is not a real attribute and is used here just for demonstration purposes. The actual error handling is done within the PHP code and cannot be controlled via shortcode attributes.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_register] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acadp_register', array( $this, 'render_register_form' ) );

Shortcode PHP function:

                    function render_register_form( $attributes, $content = null ) {	
		if ( is_user_logged_in() ) {
			return __( 'You are already signed in.', 'advanced-classifieds-and-directory-pro' );
		} elseif ( ! get_option( 'users_can_register' ) ) {
			return __( 'Registering new users is currently not allowed.', 'advanced-classifieds-and-directory-pro' );
		} 
		
		$recaptcha_settings = get_option( 'acadp_recaptcha_settings' );
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// Enqueue script dependencies		
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-validator' );		
		wp_enqueue_script( ACADP_PLUGIN_NAME );
		
		if ( isset( $recaptcha_settings['forms'] ) && in_array( 'registration', $recaptcha_settings['forms'] ) ) {
			wp_enqueue_script( ACADP_PLUGIN_NAME . '-recaptcha' );
		}
		
		// Parse shortcode attributes
		$default_attributes = array( 'redirect' => '' );
		$attributes = shortcode_atts( $default_attributes, $attributes );

		// If a valid redirect URL has been passed as request parameter, use it.
		if ( isset( $_REQUEST['redirect_to'] ) ) {
			$attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], $attributes['redirect'] );
		}
		
		// Retrieve possible errors from request parameters
		$attributes['errors'] = array();
		if ( isset( $_REQUEST['register-errors'] ) ) {
			$error_codes = explode( ',', $_REQUEST['register-errors'] );

			foreach ( $error_codes as $error_code ) {
				$error_code = sanitize_key( $error_code );
				$attributes['errors'][] = $this->get_error_message( $error_code );
			}
		}

		return $this->get_template_html( 'register', $attributes );		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-registration.php

Advanced Classifieds & Directory Pro [acadp_user_account] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode, ‘acadp_user_account’, is designed to render the user’s account page. It checks if a user is logged in and displays an error message if not. The shortcode enqueues style and script dependencies, parses shortcode attributes, and handles error messages. It also checks if the user has recently updated their account. Finally, it retrieves user data such as username, email, and full name, and uses these attributes to render the user account page using an external template.

Shortcode: [acadp_user_account]

Examples and Usage

Basic example – A shortcode that renders the user account page if the user is logged in, otherwise it returns a login form.

[acadp_user_account]

Advanced examples

Using the shortcode to display the user account page with custom attributes. In this example, we are passing an array of attributes to customize the output of the shortcode.

[acadp_user_account username="JohnDoe" email="johndoe@example.com" first_name="John" last_name="Doe"]

Here is another example where we pass an array of error codes to display specific error messages on the user account page.

[acadp_user_account update-errors="error1,error2,error3"]

Note: The actual output of these shortcodes will depend on how the ‘acadp_user_account’ shortcode is defined in your theme or plugin, and the availability of the ‘user-account’ template in your theme.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_user_account] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acadp_user_account', array( $this, 'render_user_account_page' ) );

Shortcode PHP function:

                    function render_user_account_page( $attributes, $content = null ) {		
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}	
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// Enqueue script dependencies		
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-validator' );		
		wp_enqueue_script( ACADP_PLUGIN_NAME );
		
		// Parse shortcode attributes
		$default_attributes = array();
		$attributes = shortcode_atts( $default_attributes, $attributes );
		
		// Error messages
		$errors = array();
		if ( isset( $_REQUEST['update-errors'] ) ) {
			$error_codes = explode( ',', $_REQUEST['update-errors'] );

			foreach ( $error_codes as $code ) {
				$code = sanitize_key( $code );
				$errors[] = $this->get_error_message( $code );
			}
		}
		$attributes['errors'] = $errors;
		
		// Check if user just updated his/her account
		$attributes['account_updated'] = isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'success';
		
		// Get Userdata
		$user_id = get_current_user_id();
		$user = get_userdata( $user_id );
		
		$attributes['username']   = $user->user_login;
		$attributes['email']      = $user->user_email;
      	$attributes['first_name'] = $user->first_name;
      	$attributes['last_name']  = $user->last_name;

		// Render the user account page using an external template
		return $this->get_template_html( 'user-account', $attributes );		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-registration.php

Advanced Classifieds & Directory Pro [acadp_forgot_password] Shortcode

The Advanced Classifieds and Directory Pro shortcode, ‘acadp_forgot_password’, is designed to render a forgot password form. The function checks if the user is logged in. If so, it returns a message stating the user is already signed in. If not, it enqueues style and script dependencies. The shortcode also allows for a redirect URL to be passed as a request parameter. It retrieves possible errors from the request parameters and returns the template HTML for the forgot password form.

Shortcode: [acadp_forgot_password]

Examples and Usage

Basic example – Renders the forgot password form for the Advanced Classifieds and Directory Pro plugin.

[acadp_forgot_password /]

Advanced examples

Utilizing the shortcode to display the forgot password form with a specific redirect URL after the password reset. The URL is passed as a parameter to the shortcode.

[acadp_forgot_password redirect="http://example.com/my-account" /]

Using the shortcode to display the forgot password form with multiple error messages. The error codes are passed as a comma-separated list in the ‘errors’ parameter.

[acadp_forgot_password errors="error1,error2,error3" /]

In the above example, ‘error1’, ‘error2’, and ‘error3’ are placeholders for the actual error codes that you want to display. These error codes should correspond to the ones defined in your plugin or theme.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_forgot_password] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acadp_forgot_password', array( $this, 'render_forgot_password_form' ) );

Shortcode PHP function:

                    function render_forgot_password_form( $attributes, $content = null ) {	
		if ( is_user_logged_in() ) {
			return __( 'You are already signed in.', 'advanced-classifieds-and-directory-pro' );
		}
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// Enqueue script dependencies		
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-validator' );		
		wp_enqueue_script( ACADP_PLUGIN_NAME );
		
		// Parse shortcode attributes
		$default_attributes = array( 'redirect' => '' );
		$attributes = shortcode_atts( $default_attributes, $attributes );
		
		// If a valid redirect URL has been passed as request parameter, use it.
		if ( isset( $_REQUEST['redirect_to'] ) ) {
			$attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], $attributes['redirect'] );
		}

		// Retrieve possible errors from request parameters
		$attributes['errors'] = array();
		if ( isset( $_REQUEST['errors'] ) ) {
			$error_codes = explode( ',', $_REQUEST['errors'] );

			foreach ( $error_codes as $error_code ) {
				$error_code = sanitize_key( $error_code );
				$attributes['errors'][] = $this->get_error_message( $error_code );
			}
		}

		return $this->get_template_html( 'forgot-password', $attributes );		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-registration.php

Advanced Classifieds & Directory Pro [acadp_password_reset] Shortcode

The Advanced Classifieds and Directory Pro shortcode, ‘acadp_password_reset’, allows users to reset their passwords. It checks if the user is logged in, enqueues necessary styles and scripts, and parses shortcode attributes. If a valid login, key, and redirect URL are provided, it displays a password reset form. If not, it returns an error message. This shortcode is ideal for user account management.

Shortcode: [acadp_password_reset]

Examples and Usage

Basic example – Reset password form display

[acadp_password_reset /]

This shortcode will display the password reset form. If the user is already logged in, it will display a message saying ‘You are already signed in.’

Advanced examples

Display the password reset form with a custom redirect URL after successful password reset.

[acadp_password_reset redirect='http://yourwebsite.com/welcome-back/' /]

In this example, the ‘redirect’ attribute is used to specify a URL to redirect the user to after they have successfully reset their password. If the ‘redirect’ attribute is not valid or not set, the user will be redirected to the default URL set in the plugin’s settings.

Display the password reset form with a custom login and key.

[acadp_password_reset login='userlogin' key='123456' /]

This example shows how to use the ‘login’ and ‘key’ attributes to pre-fill the form with a user’s login and key. This might be useful in certain scenarios where you want to provide a more streamlined user experience.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_password_reset] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'acadp_password_reset', array( $this, 'render_password_reset_form' ) );

Shortcode PHP function:

                    function render_password_reset_form( $attributes, $content = null ) {	
		if ( is_user_logged_in() ) {
			return __( 'You are already signed in.', 'advanced-classifieds-and-directory-pro' );
		}
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// Enqueue script dependencies		
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-validator' );		
		wp_enqueue_script( ACADP_PLUGIN_NAME );
		
		// Parse shortcode attributes
		$default_attributes = array( 'redirect' => '' );
		$attributes = shortcode_atts( $default_attributes, $attributes );

		if ( isset( $_REQUEST['login'] ) && isset( $_REQUEST['key'] ) ) {
			$attributes['login'] = sanitize_text_field( $_REQUEST['login'] );
			$attributes['key']   = sanitize_text_field( $_REQUEST['key'] );
			
			// If a valid redirect URL has been passed as request parameter, use it.
			if ( isset( $_REQUEST['redirect_to'] ) ) {
				$attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], $attributes['redirect'] );
			}

			// Error messages
			$errors = array();
			if ( isset( $_REQUEST['error'] ) ) {
				$error_codes = explode( ',', $_REQUEST['error'] );

				foreach ( $error_codes as $code ) {
					$code = sanitize_key( $code );
					$errors[] = $this->get_error_message( $code );
				}
			}
			$attributes['errors'] = $errors;

			return $this->get_template_html( 'password-reset', $attributes );
		} else {
			return __( 'Invalid password reset link.', 'advanced-classifieds-and-directory-pro' );
		}		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-registration.php

Advanced Classifieds & Directory Pro [acadp_search_form] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode, ‘acadp_search_form’, is designed to generate a search form for classifieds. This shortcode allows users to search classifieds by location, category, custom fields, and price, depending on the settings. It also supports two different styles: inline and vertical. The form’s appearance is determined by the ‘acadp-public-search-form-$style-display.php’ template.

Shortcode: [acadp_search_form]

Parameters

Here is a list of all possible acadp_search_form shortcode parameters and attributes:

  • style – type of the search form layout, can be ‘inline’ or ‘vertical’
  • location – allows search by location if set to 1
  • category – allows search by category if set to 1
  • custom_fields – allows search by custom fields if set to 1
  • price – allows search by price if set to 1

Examples and Usage

Basic example – Display a search form with default settings

[acadp_search_form /]

Advanced examples

Display a search form with the style set to vertical

[acadp_search_form style="vertical" /]

Display a search form that only allows searching by category

[acadp_search_form location=0 category=1 custom_fields=0 price=0 /]

Display a search form that allows searching by location and price, but not by category or custom fields

[acadp_search_form location=1 category=0 custom_fields=0 price=1 /]

Display a search form that allows searching by custom fields and price, but not by location or category

[acadp_search_form location=0 category=0 custom_fields=1 price=1 /]

These examples demonstrate the flexibility of the advanced-classifieds-and-directory-pro plugin shortcode. By adjusting the parameters, you can customize the search form to meet your specific needs.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_search_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_search_form", array( $this, "run_shortcode_search_form" ) );

Shortcode PHP function:

                    function run_shortcode_search_form( $atts ) {		
		$general_settings    = get_option( 'acadp_general_settings' );
		$locations_settings  = get_option( 'acadp_locations_settings' );
		$categories_settings = get_option( 'acadp_categories_settings' );
		$page_settings       = get_option( 'acadp_page_settings' );
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME . '-flatpickr' );
		wp_enqueue_style( ACADP_PLUGIN_NAME );

		wp_enqueue_script( ACADP_PLUGIN_NAME . '-flatpickr' );
		wp_enqueue_script( ACADP_PLUGIN_NAME );	
		
		// ...
		$id = wp_rand();
		
		$style = 'inline';
		if ( ! empty( $atts['style'] ) && 'vertical' == $atts['style'] ) {
			$style = 'vertical';
		}
		
		$has_location = empty( $general_settings['has_location'] ) ? 0 : 1;
		$has_price    = empty( $general_settings['has_price'] )    ? 0 : 1;

		$can_search_by_location      = isset( $atts['location'] )      ? (int) $atts['location']      : $has_location;
		$can_search_by_category      = isset( $atts['category'] )      ? (int) $atts['category']      : 1;
		$can_search_by_custom_fields = isset( $atts['custom_fields'] ) ? (int) $atts['custom_fields'] : 1;
		$can_search_by_price         = isset( $atts['price'] )         ? (int) $atts['price']         : $has_price;
		
		$span_top    = 12 / ( 1 + $can_search_by_category  + $can_search_by_location );
		$span_bottom = 12 / ( $can_search_by_price + 1 );
		
		ob_start();
		include( acadp_get_template( "search/acadp-public-search-form-$style-display.php" ) );
		return ob_get_clean();		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-search.php

Advanced Classifieds & Directory Pro [acadp_search] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is utilized to execute the search functionality in the ACADP plugin. It enables users to search for specific listings based on various parameters like category, location, and price. The shortcode retrieves the general, listings, and featured listing settings from the options table. It then customizes the query based on these settings and user inputs. The query results are displayed in a specific view, which can be a list or a map.

Shortcode: [acadp_search]

Parameters

Here is a list of all possible acadp_search shortcode parameters and attributes:

  • view – Defines the default view style of the listings.
  • featured – When set to 1, only featured listings are shown.
  • filterby – Allows filtering of listings by a specific parameter.
  • orderby – Determines the order of the listings based on a specific parameter.
  • order – Sets the direction of the listing order, ascending or descending.
  • listings_per_page – Sets the number of listings to be displayed per page.
  • pagination – When set to 1, a pagination bar is displayed.
  • header – When set to 1, a header is displayed on the listings page.

Examples and Usage

Basic example – Displaying the ACADP search results with default settings.

[acadp_search]

Advanced examples

Displaying the ACADP search results in a specific view, ordered by a certain parameter. In this example, the view is set to ‘grid’, the listings are ordered by ‘date’, and the order is ‘desc’ (descending).

[acadp_search view="grid" orderby="date" order="desc"]

Displaying the ACADP search results with a specific number of listings per page and with pagination. In this example, the listings per page are set to ’10’ and pagination is enabled.

[acadp_search listings_per_page="10" pagination="1"]

Displaying the ACADP search results with a custom header. In this example, the header is set to ‘1’ to enable it.

[acadp_search header="1"]

Displaying the ACADP search results with specific features. In this example, the featured listings are prioritized.

[acadp_search featured="1"]

Displaying the ACADP search results with a specific filter. In this example, the filter is set to ‘featured’, so only featured listings will be displayed.

[acadp_search filterby="featured"]

These shortcodes can be used in posts, pages, or widgets to display the ACADP search results with the specified parameters.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_search] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_search", array( $this, "run_shortcode_search" ) );

Shortcode PHP function:

                    function run_shortcode_search( $atts ) {		
		$shortcode = 'acadp_search';		

		$general_settings = get_option( 'acadp_general_settings' );
		$listings_settings = get_option( 'acadp_listings_settings' );
		$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
		
		$atts = shortcode_atts( array(
			'view'              => $listings_settings['default_view'],
			'featured'          => 1,
			'filterby'          => '',
			'orderby'           => $listings_settings['orderby'],
			'order'             => $listings_settings['order'],
			'listings_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
			'pagination'        => 1,
			'header'            => 1
		), $atts );
		
		$view = acadp_get_listings_current_view_name( $atts['view'] );
			
		// Enqueue style dependencies		
		wp_enqueue_style( ACADP_PLUGIN_NAME );

		if ( 'map' == $view ) {
			wp_enqueue_style( ACADP_PLUGIN_NAME . '-markerclusterer' );				
		}
		
		// Enqueue script dependencies
		if ( 'map' == $view ) {
			wp_enqueue_script( ACADP_PLUGIN_NAME . '-markerclusterer' );
			wp_enqueue_script( ACADP_PLUGIN_NAME );
		}

		// ...		
		$can_show_header           = empty( $listings_settings['display_in_header'] ) ? 0 : (int) $atts['header'];
		$pre_content               = '';
		$can_show_listings_count   = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
		$can_show_views_selector   = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
		$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
		
		$can_show_date          = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_user          = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_category      = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_views         = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_custom_fields = isset( $listings_settings['display_in_listing'] ) && in_array( 'custom_fields', $listings_settings['display_in_listing'] ) ? true : false;
		
		$can_show_images = empty( $general_settings['has_images'] ) ? false : true;

		$has_featured = apply_filters( 'acadp_has_featured', empty( $featured_listing_settings['enabled'] ) ? false : true );
		if ( $has_featured ) {
			$has_featured = $atts['featured'];
		}		
			
		$current_order       = acadp_get_listings_current_order( $atts['orderby'].'-'.$atts['order'] );
		$can_show_pagination = (int) $atts['pagination'];
		
		$has_price = empty( $general_settings['has_price'] ) ? false : true;
		$can_show_price = false;
		
		if ( $has_price ) {
			$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
		}
			
		$has_location = empty( $general_settings['has_location'] ) ? false : true;
		$can_show_location = false;
		
		if ( $has_location ) {
			$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
		}
			
		$span = 12;
		if ( $can_show_images ) $span = $span - 2;
		if ( $can_show_price ) $span = $span - 3;
		$span_middle = 'col-md-' . $span;

		// Define the query
		$paged = acadp_get_page_number();	
		
		$args = array(				
			'post_type'      => 'acadp_listings',
			'post_status'    => 'publish',
			'posts_per_page' => (int) $atts['listings_per_page'],
			'paged'          => $paged
		);
		  
		if ( isset( $_GET['q'] ) ) {
			$args['s'] = sanitize_text_field( $_GET['q'] );
		}
			
		// Define tax queries( only if applicable )
		$tax_queries = array();		
		
		if ( isset( $_GET['c'] ) && (int) $_GET['c'] > 0 ) {			
			$tax_queries[] = array(
				'taxonomy'         => 'acadp_categories',
				'field'            => 'term_id',
				'terms'            => (int) $_GET['c'],
				'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_categories', $listings_settings['include_results_from'] ) ? true : false,
			);		
		}
		
		if ( $has_location ) {		
			if ( isset( $_GET['l'] ) && (int) $_GET['l'] > 0 ) {			
				$tax_queries[] = array(
					'taxonomy'         => 'acadp_locations',
					'field'            => 'term_id',
					'terms'            => (int) $_GET['l'],
					'include_children' => isset( $listings_settings['include_results_from'] ) && in_array( 'child_locations', $listings_settings['include_results_from'] ) ? true : false,
				);		
			} elseif ( $general_settings['base_location'] > 0 ) {				
				$tax_queries[] = array(
					'taxonomy'         => 'acadp_locations',
					'field'            => 'term_id',
					'terms'            => $general_settings['base_location'],
					'include_children' => true,
				);				
			}			
		}
		
		$count_tax_queries = count( $tax_queries );		
		if ( $count_tax_queries ) {
			$args['tax_query'] = ( $count_tax_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $tax_queries ) : $tax_queries;
		}
		
		// Define meta queries( only if applicable )
		$meta_queries = array();
		
		if ( 'map' == $view ) {
			$meta_queries['hide_map'] = array(
				'key'     => 'hide_map',
				'value'   => 0,
				'compare' => '='
			);
		}
		
		if ( isset( $_GET['cf'] ) ) {			
			$cf = array_filter( $_GET['cf'] );
			
			foreach ( $cf as $key => $values ) {
				$key = sanitize_key( $key );
				$field_type = get_post_meta( $key, 'type', true );

				if ( is_array( $values ) ) {
					$values = array_values( $values );
					
					if ( 'range' == $field_type ) {							
						$values = array_filter( $values );
						
						if ( $n = count( $values ) ) {
							if ( 2 == $n ) {
								$meta_queries[] = array(
									'key'		=> $key,
									'value'		=> array_map( 'intval', $values ),
									'type'      => 'NUMERIC',
									'compare'	=> 'BETWEEN'
								);
							} else {
								if ( empty( $values[0] ) ) {
									$meta_queries[] = array(
										'key'		=> $key,
										'value'		=> (int) $values[1],
										'type'      => 'NUMERIC',
										'compare'	=> '<='
									);
								} else {
									$meta_queries[] = array(
										'key'		=> $key,
										'value'		=> (int) $values[0],
										'type'      => 'NUMERIC',
										'compare'	=> '>='
									);
								}
							}	
						}			
					} else {
						if ( count( $values ) > 1 ) {
							$sub_meta_queries = array();
							
							foreach ( $values as $value ) {
								$sub_meta_queries[] = array(
									'key'		=> $key,
									'value'		=> sanitize_text_field( $value ),
									'compare'	=> 'LIKE'
								);
							}
							
							$meta_queries[] = array_merge( array( 'relation' => 'OR' ), $sub_meta_queries );
						} else {					
							$meta_queries[] = array(
								'key'		=> $key,
								'value'		=> sanitize_text_field( $values[0] ),
								'compare'	=> 'LIKE'
							);					
						}	
					}					
				} else {						
					if ( 'date' == $field_type || 'datetime' == $field_type ) {
						$range_separator = __( 'to', 'advanced-classifieds-and-directory-pro' );
						
						if ( strpos( $values, $range_separator ) !== false ) {
							$dates = explode( $range_separator, $values );
							$dates = array_map( 'sanitize_text_field', $dates );						

							$meta_queries[] = array(
								'key'     => $key,
								'value'   => array( $dates[0], $dates[1] ),
								'compare' => 'BETWEEN',
            					'type'    => 'DATE'
							);
						} else {
							$meta_queries[] = array(
								'key'		=> $key,
								'value'		=> sanitize_text_field( $values ),
								'compare'	=> 'LIKE'
							);
						} 
					} else {
						$operator = ( 'text' == $field_type || 'textarea' == $field_type || 'url' == $field_type ) ? 'LIKE' : '=';
						
						$meta_queries[] = array(
							'key'		=> $key,
							'value'		=> sanitize_text_field( $values ),
							'compare'	=> $operator
						);
					}					
				}				
			}				
		}
		
		if ( $has_price ) {		
			$meta_queries['price'] = array(
				'key'     => 'price',
				'type'    => 'NUMERIC',
				'compare' => 'EXISTS',
			);
						
			if ( isset( $_GET['price'] ) ) {			
				$price = array_filter( $_GET['price'] );
		
				if ( $n = count( $price ) ) {				
					if ( 2 == $n ) {
						$meta_queries[] = array(
							'key'		=> 'price',
							'value'		=> array_map( 'intval', $price ),
							'type'      => 'NUMERIC',
							'compare'	=> 'BETWEEN'
						);
					} else {
						if ( empty( $price[0] ) ) {
							$meta_queries[] = array(
								'key'		=> 'price',
								'value'		=> (int) $price[1],
								'type'      => 'NUMERIC',
								'compare'	=> '<='
							);
						} else {
							$meta_queries[] = array(
								'key'		=> 'price',
								'value'		=> (int) $price[0],
								'type'      => 'NUMERIC',
								'compare'	=> '>='
							);
						}
					}			
				}					
			}			
		}
			
		if ( $has_featured ) {			
			if ( 'featured' == $atts['filterby'] ) {
				$meta_queries['featured'] = array(
					'key'     => 'featured',
					'value'   => 1,
					'compare' => '='
				);
			} else {
				$meta_queries['featured'] = array(
					'key'     => 'featured',
					'type'    => 'NUMERIC',
					'compare' => 'EXISTS',
				);
			}				
		}

		switch ( $current_order ) {
			case 'title-asc' :
				if ( $has_featured ) {
					$args['orderby']  = array(
						'featured' => 'DESC',
						'title'    => 'ASC',
					);
				} else {
					$args['orderby'] = 'title';
					$args['order']   = 'ASC';
				};
				break;
			case 'title-desc' :
				if ( $has_featured ) {
					$args['orderby']  = array(
						'featured' => 'DESC',
						'title'    => 'DESC',
					);
				} else {
					$args['orderby'] = 'title';
					$args['order']   = 'DESC';
				};
				break;
			case 'date-asc' :
				if ( $has_featured ) {
					$args['orderby']  = array(
						'featured' => 'DESC',
						'date'     => 'ASC',
					);
				} else {
					$args['orderby'] = 'date';
					$args['order']   = 'ASC';
				};
				break;
			case 'date-desc' :
				if ( $has_featured ) {
					$args['orderby']  = array(
						'featured' => 'DESC',
						'date'     => 'DESC',
					);
				} else {
					$args['orderby'] = 'date';
					$args['order']   = 'DESC';
				};
				break;
			case 'price-asc' :
				if ( $has_featured ) {
					$args['orderby']  = array( 
						'featured' => 'DESC',
						'price'    => 'ASC',
					);
				} else {
					$args['meta_key'] = 'price';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'ASC';
				};
				break;
			case 'price-desc' :
				if ( $has_featured ) {
					$args['orderby']  = array( 
						'featured' => 'DESC',
						'price'    => 'DESC',
					);
				} else {
					$args['meta_key'] = 'price';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'DESC';
				};
				break;
			case 'views-asc' :
				if ( $has_featured ) {
					$meta_queries['views'] = array(
						'key'     => 'views',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);
		
					$args['orderby']  = array( 
						'featured' => 'DESC',
						'views'    => 'ASC',
					);
				} else {
					$args['meta_key'] = 'views';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'ASC';
				};
				break;
			case 'views-desc' :
				if ( $has_featured ) {
					$meta_queries['views'] = array(
						'key'     => 'views',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);
					
					$args['orderby']  = array( 
						'featured' => 'DESC',
						'views'    => 'DESC',
					);
				} else {
					$args['meta_key'] = 'views';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'DESC';
				};
				break;
			case 'rand-asc' :
			case 'rand-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = 'meta_value_num rand';
				} else {
					$args['orderby'] = 'rand';
				};
				break;
		}
		
		$count_meta_queries = count( $meta_queries );
		if ( $count_meta_queries ) {
			$args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : $meta_queries;
		}		

		add_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );	
		
		$args = apply_filters( 'acadp_query_args', $args, $shortcode );
		$acadp_query = new WP_Query( $args );

		remove_filter( 'posts_where', array( $this, 'posts_where' ), 10, 2 );
			
		// Start the Loop
		global $post;
		
		// Process output
		if ( $acadp_query->have_posts() ) {			
			ob_start();
			include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
			return ob_get_clean();				
		} else {		
			return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';			
		}		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-search.php

Advanced Classifieds & Directory Pro [acadp_user_listings] Shortcode

The Advanced Classifieds and Directory Pro shortcode `acadp_user_listings` is designed to display the listings of a specific user or the current logged-in user. This shortcode retrieves the user’s slug and fetches their listings. It offers various display settings, including the ability to show listings count, views selector, and order by dropdown in the header. It also allows for the display of date, user, category, views, custom fields, images, price, and location in the listing. The shortcode supports pagination and is equipped with query arguments for sorting listings by title, date, price, views, or randomly. If no listings are found, it returns a “No results found” message.

Shortcode: [acadp_user_listings]

Parameters

Here is a list of all possible acadp_user_listings shortcode parameters and attributes:

  • id – Identifier of a specific user.
  • view – Determines the layout of the listings.
  • featured – Enables or disables featured listings.
  • filterby – Allows listings filtering by certain criteria.
  • orderby – Decides the order of the listings.
  • order – Specifies the sort order of the listings.
  • listings_per_page – Sets the number of listings per page.
  • pagination – Turns on or off the pagination.
  • header – Controls the visibility of the header.

Examples and Usage

Basic example – Displaying user listings by referencing user id.

[acadp_user_listings id=1 /]

Advanced examples

Using the shortcode to display user listings with specific view, filter, order, and pagination settings. The listings will be displayed in grid view, filtered by featured listings, ordered by title in ascending order, and with pagination enabled.

[acadp_user_listings view="grid" featured=1 filterby="featured" orderby="title" order="asc" listings_per_page=10 pagination=1 header=1 /]

Using the shortcode to display user listings without any header and with specific listings per page settings. The listings will be displayed without any header and with 5 listings per page.

[acadp_user_listings header=0 listings_per_page=5 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_user_listings] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_user_listings", array( $this, "run_shortcode_user_listings" ) );

Shortcode PHP function:

                    function run_shortcode_user_listings( $atts ) {	
		$shortcode = 'acadp_user_listings';
		
		$user_slug = acadp_get_user_slug();
		if ( '' == $user_slug ) {
			if ( ! empty( $atts['id'] ) ) {
				$user_slug = get_the_author_meta( 'user_nicename', (int) $atts['id'] );	
			} elseif ( is_user_logged_in() ) {
				$user_slug = get_the_author_meta( 'user_nicename', get_current_user_id() );				
			}
		}
		
		if ( '' != $user_slug ) {		
			$general_settings = get_option( 'acadp_general_settings' );
			$listings_settings = get_option( 'acadp_listings_settings' );
			$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
			
			$atts = shortcode_atts( array(
				'view'              => $listings_settings['default_view'],
				'featured'          => 1,
				'filterby'          => '',
				'orderby'           => $listings_settings['orderby'],
				'order'             => $listings_settings['order'],
				'listings_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
				'pagination'        => 1,
				'header'            => 1
			), $atts );
		
			$view = acadp_get_listings_current_view_name( $atts['view'] );
		
			// Enqueue style dependencies
			wp_enqueue_style( ACADP_PLUGIN_NAME );

			if ( 'map' == $view ) {
				wp_enqueue_style( ACADP_PLUGIN_NAME . '-markerclusterer' );				
			}
		
			// Enqueue script dependencies
			if ( 'map' == $view ) {
				wp_enqueue_script( ACADP_PLUGIN_NAME . '-markerclusterer' );
				wp_enqueue_script( ACADP_PLUGIN_NAME );
			}
		
			// ...
			$can_show_header           = empty( $listings_settings['display_in_header'] ) ? 0 : (int) $atts['header'];
			$pre_content               = '';
			$can_show_listings_count   = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
			$can_show_views_selector   = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
			$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
					
			$can_show_date          = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_user          = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_category      = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_views         = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
			$can_show_custom_fields = isset( $listings_settings['display_in_listing'] ) && in_array( 'custom_fields', $listings_settings['display_in_listing'] ) ? true : false;

			$can_show_images = empty( $general_settings['has_images'] ) ? false : true;			
			
			$has_featured = apply_filters( 'acadp_has_featured', empty( $featured_listing_settings['enabled'] ) ? false : true );
			if ( $has_featured ) {
				$has_featured = $atts['featured'];
			}
			
			$current_order       = acadp_get_listings_current_order( $atts['orderby'] . '-' . $atts['order'] );
			$can_show_pagination = (int) $atts['pagination'];
			
			$has_price = empty( $general_settings['has_price'] ) ? false : true;
			$can_show_price = false;
		
			if ( $has_price ) {
				$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
			}
			
			$has_location = empty( $general_settings['has_location'] ) ? false : true;
			$can_show_location = false;
		
			if ( $has_location ) {
				$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
			}
		
			$span = 12;
			if ( $can_show_images ) $span = $span - 2;
			if ( $can_show_price ) $span = $span - 3;
			$span_middle = 'col-md-' . $span;

			// Define the query
			$paged = acadp_get_page_number();
			
			$args = array(				
				'post_type'      => 'acadp_listings',
				'post_status'    => 'publish',
				'posts_per_page' => (int) $atts['listings_per_page'],
				'paged'          => $paged,
				'author_name'    => $user_slug,
	  		);
			
			if ( $has_location && $general_settings['base_location'] > 0 ) {			
				$args['tax_query'] = array(
					array(
						'taxonomy'         => 'acadp_locations',
						'field'            => 'term_id',
						'terms'            => $general_settings['base_location'],
						'include_children' => true,
					),
				);				
			}
			
			$meta_queries = array();
			
			if ( 'map' == $view ) {
				$meta_queries['hide_map'] = array(
					'key'     => 'hide_map',
					'value'   => 0,
					'compare' => '='
				);
			}
			
			if ( $has_featured ) {			
				if ( 'featured' == $atts['filterby'] ) {
					$meta_queries['featured'] = array(
						'key'     => 'featured',
						'value'   => 1,
						'compare' => '='
					);
				} else {
					$meta_queries['featured'] = array(
						'key'     => 'featured',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);
				}					
			}
		
			switch ( $current_order ) {
				case 'title-asc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'title'          => 'ASC',
						);
					} else {
						$args['orderby'] = 'title';
						$args['order']   = 'ASC';
					};
					break;
				case 'title-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'title'          => 'DESC',
						);
					} else {
						$args['orderby'] = 'title';
						$args['order']   = 'DESC';
					};
					break;
				case 'date-asc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'date'           => 'ASC',
						);
					} else {
						$args['orderby'] = 'date';
						$args['order']   = 'ASC';
					};
					break;
				case 'date-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = array(
							'meta_value_num' => 'DESC',
							'date'           => 'DESC',
						);
					} else {
						$args['orderby'] = 'date';
						$args['order']   = 'DESC';
					};
					break;
				case 'price-asc' :
					if ( $has_featured ) {
						$meta_queries['price'] = array(
							'key'     => 'price',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'price'    => 'ASC',
						);
					} else {
						$args['meta_key'] = 'price';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'ASC';
					};
					break;
				case 'price-desc' :
					if ( $has_featured ) {
						$meta_queries['price'] = array(
							'key'     => 'price',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'price'    => 'DESC',
						);
					} else {
						$args['meta_key'] = 'price';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'DESC';
					};
					break;
				case 'views-asc' :
					if ( $has_featured ) {
						$meta_queries['views'] = array(
							'key'     => 'views',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'views'    => 'ASC',
						);
					} else {
						$args['meta_key'] = 'views';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'ASC';
					};
					break;
				case 'views-desc' :
					if ( $has_featured ) {
						$meta_queries['views'] = array(
							'key'     => 'views',
							'type'    => 'NUMERIC',
							'compare' => 'EXISTS',
						);

						$args['orderby']  = array( 
							'featured' => 'DESC',
							'views'    => 'DESC',
						);
					} else {
						$args['meta_key'] = 'views';
						$args['orderby']  = 'meta_value_num';
						$args['order']    = 'DESC';
					};
					break;
				case 'rand-asc' :
				case 'rand-desc' :
					if ( $has_featured ) {
						$args['meta_key'] = 'featured';
						$args['orderby']  = 'meta_value_num rand';
					} else {
						$args['orderby'] = 'rand';
					};
					break;
			}
			
			$count_meta_queries = count( $meta_queries );
			if ( $count_meta_queries ) {
				$args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : $meta_queries;
			}
			
			$args = apply_filters( 'acadp_query_args', $args, $shortcode );
			$acadp_query = new WP_Query( $args );
			
			// Start the Loop
			global $post;
			
			// Process output
			if ( $acadp_query->have_posts() ) {
				ob_start();
				include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
				return ob_get_clean();			
			} else {		
				return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
			}		
		}		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-user.php

Advanced Classifieds & Directory Pro [acadp_user_dashboard] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is a useful tool for user interaction. It allows users to access a personalized dashboard once they are logged in. The function “run_shortcode_user_dashboard” is activated when the shortcode is used. It checks if a user is logged in and if not, it returns the login form. If the user is logged in, it retrieves the user’s ID and data, enqueues the ACADP style dependencies and includes the user dashboard display template.

Shortcode: [acadp_user_dashboard]

Examples and Usage

Basic example – displays the user dashboard for the logged-in user.

[acadp_user_dashboard /]

Advanced examples:

Displaying the user dashboard for the logged-in user with a specific style sheet. This is useful if you have a custom style sheet that you want to apply to the user dashboard.

[acadp_user_dashboard style="custom-style" /]

Displaying the user dashboard for the logged-in user and include additional content before and after the dashboard. The ‘before’ and ‘after’ parameters allow you to add custom content or actions before and after the user dashboard.

[acadp_user_dashboard before="Before Dashboard Content" after="After Dashboard Content" /]

Note: In the above examples, ‘custom-style’, ‘Before Dashboard Content’, and ‘After Dashboard Content’ are placeholders. Replace them with your actual style sheet name or content.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_user_dashboard] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_user_dashboard", array( $this, "run_shortcode_user_dashboard" ) );

Shortcode PHP function:

                    function run_shortcode_user_dashboard() {		
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}		

		$shortcode = 'acadp_user_dashboard';
		
		$userid = get_current_user_id();
		$user = get_userdata( $userid );
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// ...		
		ob_start();
		do_action( 'acadp_before_user_dashboard_content' );
		include( acadp_get_template( "user/acadp-public-user-dashboard-display.php" ) );
		do_action( 'acadp_after_user_dashboard_content' );
		return ob_get_clean();		
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-user.php

Advanced Classifieds & Directory Pro [acadp_listing_form] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is used to create a listing form. It checks user permissions, enqueues necessary scripts and styles, and sets up the form fields. It first verifies if the user is logged in, then checks if the user has permission to edit the listing. If not, it returns an error message. The shortcode also loads the necessary CSS and JS files for the form’s functionality and appearance. It then sets up the form fields based on the plugin’s general settings, such as enabling/disabling parent categories, text editor choice, and optional fields like price, images, video, and location. Finally, it loads the appropriate template for the listing form and returns the generated HTML.

Shortcode: [acadp_listing_form]

Examples and Usage

Basic example – Display the listing form using the shortcode without any parameters.

[acadp_listing_form]

Advanced examples:

Display the listing form with a specific listing ID. This will load the form with the details of the listing with the provided ID for editing.

[acadp_listing_form id=5]

Display the listing form for a specific user. This will load the form with the details of the listings owned by the user with the provided user ID.

[acadp_listing_form user_id=3]

Display the listing form with a pre-selected category. This will load the form with the selected category already chosen.

[acadp_listing_form category="vehicles"]

Combining multiple parameters. This will load the form for the user with ID 3, with the listing with ID 5 pre-loaded for editing and the category ‘vehicles’ already selected.

[acadp_listing_form id=5 user_id=3 category="vehicles"]
Note: The actual functionality of these shortcodes depends on the implementation of the ‘run_shortcode_listing_form’ function. The examples provided assume that the function supports these parameters.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_listing_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_listing_form", array( $this, "run_shortcode_listing_form" ) );

Shortcode PHP function:

                    function run_shortcode_listing_form() {		
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}		
		
		$post_id  = 'edit' == get_query_var( 'acadp_action' ) ? get_query_var( 'acadp_listing', 0 ) : 0;
		$has_permission = true;
		
		if ( $post_id > 0 ) {
			if ( ! acadp_current_user_can('edit_acadp_listing', $post_id) ) {
				$has_permission = false;
			}
		} elseif ( ! acadp_current_user_can('edit_acadp_listings') ) {
			$has_permission = false;
		}
		
		if ( ! $has_permission ) {
			return __( 'You do not have sufficient permissions to access this page.', 'advanced-classifieds-and-directory-pro' );
		}
		
		$shortcode = 'acadp_listing_form';
		
		$general_settings    = get_option( 'acadp_general_settings' );
		$recaptcha_settings  = get_option( 'acadp_recaptcha_settings' );
		$locations_settings  = get_option( 'acadp_locations_settings' );
		$categories_settings = get_option( 'acadp_categories_settings' );				
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME . '-map' );				
		wp_enqueue_style( ACADP_PLUGIN_NAME . '-flatpickr' );
		wp_enqueue_style( ACADP_PLUGIN_NAME );
		
		// Enqueue script dependencies		
		wp_enqueue_script( 'jquery-form', array('jquery'), false, true );		
		wp_enqueue_script( 'jquery-ui-sortable' );
		wp_enqueue_script( 'jquery-touch-punch' );
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-bootstrap' );		
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-validator' );			
		wp_enqueue_script( ACADP_PLUGIN_NAME . '-map' );
		
		if ( isset( $recaptcha_settings['forms'] ) && in_array( 'listing', $recaptcha_settings['forms'] ) ) {
			wp_enqueue_script( ACADP_PLUGIN_NAME . "-recaptcha" );
		}

		wp_enqueue_script( ACADP_PLUGIN_NAME . '-flatpickr' );
		wp_enqueue_script( ACADP_PLUGIN_NAME );	

		// ...
		$has_draft = 1;
		$category  = 0;
		$default_location = '';

		$disable_parent_categories = empty( $general_settings['disable_parent_categories'] ) ? false : true;		
		$editor = ! empty( $general_settings['text_editor'] ) ? $general_settings['text_editor'] : 'wp_editor';
		
		$can_add_price    = empty( $general_settings['has_price'] )    ? false : true;
		$can_add_images   = empty( $general_settings['has_images'] )   ? false : true;
		$can_add_video    = empty( $general_settings['has_video'] )    ? false : true;	
		$can_add_location = empty( $general_settings['has_location'] ) ? false : true;
		$has_map          = empty( $general_settings['has_map'] )      ? false : true;
		$mark_as_sold     = empty( $general_settings['mark_as_sold'] ) ? false : true;
		
		$images_limit = apply_filters( 'acadp_images_limit', (int) $general_settings['maximum_images_per_listing'], $post_id );
		
		if ( $can_add_location ) {
			$location = ( $general_settings['default_location'] > 0 ) ? $general_settings['default_location'] : $general_settings['base_location'];
			if ( $location > 0 ) {
				if ( $term = get_term_by( 'id', $location, 'acadp_locations' ) ) {
					$default_location = $term->name;
				}
			}
		}

		if ( $post_id > 0 ) {			
			$post = get_post( $post_id );
			setup_postdata( $post );
			
			$post_meta = get_post_meta( $post_id);
			
			if ( $post->post_status !== 'draft' ) {
				$has_draft = 0;
			}
			
			$category = wp_get_object_terms( $post_id, 'acadp_categories', array( 'fields' => 'ids' ) );
			$category = $category[0];
			
			if ( $can_add_location ) {
				$location = wp_get_object_terms( $post_id, 'acadp_locations', array( 'fields' => 'ids' ) );
				$location = ! empty( $location ) ? $location[0] : -1;
			}			
		}
		
		ob_start();
		include( acadp_get_template( "user/acadp-public-edit-listing-display.php" ) );
		wp_reset_postdata(); // Restore global post data stomped by the_post()
		return ob_get_clean();	
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-user.php

Advanced Classifieds & Directory Pro [acadp_manage_listings] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is used to manage listings on a WordPress website. It checks if a user is logged in and has the necessary permissions to edit listings. It fetches general, listings, page, and featured listing settings. It determines the ability to show images, renew listings, and show location. It also enables promotion of listings if the featured listing is enabled and priced. The shortcode then defines a query to fetch listings authored by the current user. It starts a loop and includes a template for displaying the listings. The shortcode resets post data to restore the original query.

Shortcode: [acadp_manage_listings]

Examples and Usage

Basic example – The shortcode provides a way to manage the listings for logged-in users. If the user is not logged in, it will return a login form.

[acadp_manage_listings]

Advanced examples

Use the shortcode to display a specific number of listings per page. This can be achieved by adding the ‘listings_per_page’ attribute to the shortcode and setting it to the desired number.

[acadp_manage_listings listings_per_page=10]

Include a search field in the listings by adding the ‘s’ attribute to the shortcode. The value of ‘s’ will be used as the search query.

[acadp_manage_listings s="cars"]

Display listings from a specific author by adding the ‘author’ attribute to the shortcode. The value should be the ID of the author.

[acadp_manage_listings author=1]

Note: The advanced examples assume that the shortcode supports these attributes. If it doesn’t, these examples will not work as expected.

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_manage_listings] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_manage_listings", array( $this, "run_shortcode_manage_listings" ) );

Shortcode PHP function:

                    function run_shortcode_manage_listings() {	
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}		

		if ( ! acadp_current_user_can('edit_acadp_listings') ) {
			return __( 'You do not have sufficient permissions to access this page.', 'advanced-classifieds-and-directory-pro' );
		}
		
		$shortcode = 'acadp_manage_listings';
		
		$general_settings          = get_option( 'acadp_general_settings' );
		$listings_settings         = get_option( 'acadp_listings_settings' );
		$page_settings             = get_option( 'acadp_page_settings' );
		$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
		
		$can_show_images = empty( $general_settings['has_images'] ) ? false : true;
		$can_renew       = empty( $general_settings['has_listing_renewal'] ) ? false : true;
		$has_location    = empty( $general_settings['has_location'] ) ? false : true;
			
		$span = 9;
		if ( $can_show_images ) $span = 7;
		$span_middle = 'col-md-'.$span;
		
		$can_promote = false;
		if ( ! empty( $featured_listing_settings['enabled'] ) && $featured_listing_settings['price'] > 0 ) {
			$can_promote = true;
		}
		$can_promote = apply_filters( 'acadp_can_promote', $can_promote );
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );

		// Define the query
		$paged = acadp_get_page_number();
			
		$args = array(				
			'post_type'      => 'acadp_listings',
			'post_status'    => 'any',
			'posts_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
			'paged'          => $paged,
			'author'         => get_current_user_id(),
			's'              => isset( $_REQUEST['u'] ) ? sanitize_text_field( $_REQUEST['u'] ) : ''
	  	);
			
		$acadp_query = new WP_Query( $args );
			
		// Start the Loop
		global $post;
			
		// Process output
		ob_start();
		include( acadp_get_template( "user/acadp-public-manage-listings-display.php" ) );
		wp_reset_postdata(); // Use reset postdata to restore orginal query
		return ob_get_clean();			
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-user.php

Advanced Classifieds & Directory Pro [acadp_favourite_listings] Shortcode

The Advanced Classifieds and Directory Pro (ACADP) shortcode is used to display a user’s favorite listings. It checks if a user is logged in, fetches the general, listings, and featured listing settings, and enqueues necessary styles and scripts. It defines the layout, filters, and sort order of the listings. It also determines which elements (date, user, category, views, custom fields, images, price, location) to display in the listings and adjusts the layout accordingly. The shortcode then queries the database for the user’s favorite listings, sorting and filtering them based on the settings, and displays them. If no listings are found, it displays a ‘No results found’ message.

Shortcode: [acadp_favourite_listings]

Parameters

Here is a list of all possible acadp_favourite_listings shortcode parameters and attributes:

  • view – Defines the default view of the listings
  • featured – Controls whether featured listings are shown
  • filterby – Allows filtering of the listings
  • orderby – Determines the order of the listings
  • order – Specifies the direction of the ordering
  • listings_per_page – Sets the number of listings per page
  • pagination – Controls whether pagination is shown
  • header – Controls whether the header is shown

Examples and Usage

Basic example – Displaying the favourite listings of a logged-in user in a default view.

[acadp_favourite_listings /]

Advanced examples

Displaying the favourite listings of a logged-in user in a map view. The listings will be ordered by title in ascending order.

[acadp_favourite_listings view="map" orderby="title" order="asc" /]

Displaying the favourite listings of a logged-in user in a list view with pagination. The listings will be ordered by date in descending order and only 10 listings will be displayed per page.

[acadp_favourite_listings view="list" orderby="date" order="desc" listings_per_page="10" pagination="1" /]

Displaying the favourite listings of a logged-in user without the header. The listings will be ordered by views in ascending order.

[acadp_favourite_listings header="0" orderby="views" order="asc" /]

Displaying the favourite listings of a logged-in user with the featured listings filtered. The listings will be ordered by price in descending order.

[acadp_favourite_listings filterby="featured" orderby="price" order="desc" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [acadp_favourite_listings] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( "acadp_favourite_listings", array( $this, "run_shortcode_favourite_listings" ) );

Shortcode PHP function:

                    function run_shortcode_favourite_listings( $atts ) {	
		if ( ! is_user_logged_in() ) {		
			return acadp_login_form();			
		}	
		
		$shortcode = 'acadp_favourite_listings';
		
		$general_settings = get_option( 'acadp_general_settings' );
		$listings_settings = get_option( 'acadp_listings_settings' );
		$featured_listing_settings = get_option( 'acadp_featured_listing_settings' );
		
		$atts = shortcode_atts( array(
			'view'              => $listings_settings['default_view'],
			'featured'          => 1,
			'filterby'          => '',
			'orderby'           => $listings_settings['orderby'],
			'order'             => $listings_settings['order'],
			'listings_per_page' => ! empty( $listings_settings['listings_per_page'] ) ? $listings_settings['listings_per_page'] : -1,
			'pagination'        => 1,
			'header'            => 1
		), $atts );
		
		$view = acadp_get_listings_current_view_name( $atts['view'] );
		
		// Enqueue style dependencies
		wp_enqueue_style( ACADP_PLUGIN_NAME );

		if ( 'map' == $view ) {
			wp_enqueue_style( ACADP_PLUGIN_NAME . '-markerclusterer' );				
		}
		
		// Enqueue script dependencies
		if ( 'map' == $view ) {
			wp_enqueue_script( ACADP_PLUGIN_NAME . '-markerclusterer' );
		}

		wp_enqueue_script( ACADP_PLUGIN_NAME );
		
		// ...
		$can_show_header           = empty( $listings_settings['display_in_header'] ) ? 0 : (int) $atts['header'];
		$pre_content               = '';
		$can_show_listings_count   = $can_show_header && in_array( 'listings_count', $listings_settings['display_in_header'] ) ? true : false;
		$can_show_views_selector   = $can_show_header && in_array( 'views_selector', $listings_settings['display_in_header'] ) ? true : false;
		$can_show_orderby_dropdown = $can_show_header && in_array( 'orderby_dropdown', $listings_settings['display_in_header'] ) ? true : false;
			
		$can_show_date          = isset( $listings_settings['display_in_listing'] ) && in_array( 'date', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_user          = isset( $listings_settings['display_in_listing'] ) && in_array( 'user', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_category      = isset( $listings_settings['display_in_listing'] ) && in_array( 'category', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_views         = isset( $listings_settings['display_in_listing'] ) && in_array( 'views', $listings_settings['display_in_listing'] ) ? true : false;
		$can_show_custom_fields = isset( $listings_settings['display_in_listing'] ) && in_array( 'custom_fields', $listings_settings['display_in_listing'] ) ? true : false;
		
		$can_show_images = empty( $general_settings['has_images'] ) ? false : true;
		
		$has_featured = apply_filters( 'acadp_has_featured', empty( $featured_listing_settings['enabled'] ) ? false : true );
		if ( $has_featured ) {
			$has_featured = $atts['featured'];
		}
				
		$current_order       = acadp_get_listings_current_order( $atts['orderby'] . '-' . $atts['order'] );
		$can_show_pagination = (int) $atts['pagination'];
		
		$has_price = empty( $general_settings['has_price'] ) ? false : true;
		$can_show_price = false;
		
		if ( $has_price ) {
			$can_show_price = isset( $listings_settings['display_in_listing'] ) && in_array( 'price', $listings_settings['display_in_listing'] ) ? true : false;
		}
			
		$has_location = empty( $general_settings['has_location'] ) ? false : true;
		$can_show_location = false;
		
		if ( $has_location ) {
			$can_show_location = isset( $listings_settings['display_in_listing'] ) && in_array( 'location', $listings_settings['display_in_listing'] ) ? true : false;
		}
		
		$span = 12;
		if ( $can_show_images ) $span = $span - 2;
		if ( $can_show_price ) $span = $span - 3;
		$span_middle = 'col-md-' . $span;
		
		// Define the query
		$paged = acadp_get_page_number();
		$favourite_posts = get_user_meta( get_current_user_id(), 'acadp_favourites', true );
			
		$args = array(				
			'post_type'      => 'acadp_listings',
			'post_status'    => 'publish',		
			'posts_per_page' => (int) $atts['listings_per_page'],
			'paged'          => $paged,
			'post__in'       => ! empty( $favourite_posts ) ? $favourite_posts : array(0)
	  	);
		
		if ( $has_location && $general_settings['base_location'] > 0 ) {			
			$args['tax_query'] = array(
				array(
					'taxonomy'         => 'acadp_locations',
					'field'            => 'term_id',
					'terms'            => $general_settings['base_location'],
					'include_children' => true,
				),
			);				
		}
			
		$meta_queries = array();
			
		if ( 'map' == $view ) {
			$meta_queries['hide_map'] = array(
				'key'     => 'hide_map',
				'value'   => 0,
				'compare' => '='
			);
		}
		
		if ( $has_featured ) {			
			if ( 'featured' == $atts['filterby'] ) {
				$meta_queries['featured'] = array(
					'key'     => 'featured',
					'value'   => 1,
					'compare' => '='
				);
			} else {
				$meta_queries['featured'] = array(
					'key'     => 'featured',
					'type'    => 'NUMERIC',
					'compare' => 'EXISTS',
				);
			}				
		}
			
		switch ( $current_order ) {
			case 'title-asc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'title'          => 'ASC',
					);
				} else {
					$args['orderby'] = 'title';
					$args['order']   = 'ASC';
				};
				break;
			case 'title-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'title'          => 'DESC',
					);
				} else {
					$args['orderby'] = 'title';
					$args['order']   = 'DESC';
				};
				break;
			case 'date-asc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'date'           => 'ASC',
					);
				} else {
					$args['orderby'] = 'date';
					$args['order']   = 'ASC';
				};
				break;
			case 'date-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = array(
						'meta_value_num' => 'DESC',
						'date'           => 'DESC',
					);
				} else {
					$args['orderby'] = 'date';
					$args['order']   = 'DESC';
				};
				break;
			case 'price-asc' :
				if ( $has_featured ) {
					$meta_queries['price'] = array(
						'key'     => 'price',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);
					
					$args['orderby']  = array( 
						'featured' => 'DESC',
						'price'    => 'ASC',
					);
				} else {
					$args['meta_key'] = 'price';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'ASC';
				};
				break;
			case 'price-desc' :
				if ( $has_featured ) {
					$meta_queries['price'] = array(
						'key'     => 'price',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'price'    => 'DESC',
					);
				} else {
					$args['meta_key'] = 'price';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'DESC';
				};
				break;
			case 'views-asc' :
				if ( $has_featured ) {
					$meta_queries['views'] = array(
						'key'     => 'views',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'views'    => 'ASC',
					);
				} else {
					$args['meta_key'] = 'views';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'ASC';
				};
				break;
			case 'views-desc' :
				if ( $has_featured ) {
					$meta_queries['views'] = array(
						'key'     => 'views',
						'type'    => 'NUMERIC',
						'compare' => 'EXISTS',
					);

					$args['orderby']  = array( 
						'featured' => 'DESC',
						'views'    => 'DESC',
					);
				} else {
					$args['meta_key'] = 'views';
					$args['orderby']  = 'meta_value_num';
					$args['order']    = 'DESC';
				};
				break;
			case 'rand-asc' :
			case 'rand-desc' :
				if ( $has_featured ) {
					$args['meta_key'] = 'featured';
					$args['orderby']  = 'meta_value_num rand';
				} else {
					$args['orderby'] = 'rand';
				};
				break;
		}
			
		$count_meta_queries = count( $meta_queries );
		if ( $count_meta_queries ) {
			$args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : $meta_queries;
		}
			
		$acadp_query = new WP_Query( $args );
			
		// Start the Loop
		global $post;
			
		// Process output
		if ( $acadp_query->have_posts() ) {
			ob_start();
			include( acadp_get_template( "listings/acadp-public-listings-$view-display.php" ) );
			return ob_get_clean();		
		} else {		
			return '<span>' . __( 'No results found', 'advanced-classifieds-and-directory-pro' ) . '</span>';		
		}			
	}
                    

Code file location:

advanced-classifieds-and-directory-pro/advanced-classifieds-and-directory-pro/public/class-acadp-public-user.php

Conclusion

Now that you’ve learned how to embed the Advanced Classifieds & Directory Pro Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *