| 1: | <?php |
| 2: | /** |
| 3: | * SHORTCODE :: Listing [listing] |
| 4: | * |
| 5: | * @package EPL |
| 6: | * @subpackage Shortcode/Listing |
| 7: | * @copyright Copyright (c) 2020, Merv Barrett |
| 8: | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9: | * @since 1.0 |
| 10: | * @since 3.4 support for third and fourth agents. |
| 11: | */ |
| 12: | |
| 13: | // Exit if accessed directly. |
| 14: | if ( ! defined( 'ABSPATH' ) ) { |
| 15: | exit; |
| 16: | } |
| 17: | |
| 18: | // phpcs:disable WordPress.DB.SlowDBQuery |
| 19: | |
| 20: | /** |
| 21: | * Listing Shortcode [listing] |
| 22: | * |
| 23: | * This shortcode allows for you to specify the property type(s) using |
| 24: | * [listing post_type="property,rental" status="current,sold,leased" template="default"] option. You can also |
| 25: | * limit the number of entries that display. using [listing limit="5"] |
| 26: | * |
| 27: | * Since 3.6 [listing] and [listing_advanced] are the same shortcode, so [listing] also takes |
| 28: | * feature="pool", location_id="12", open_house="true", auction="true", post__in="1,2", |
| 29: | * orderby_clause and the other [listing_advanced] options. |
| 30: | * |
| 31: | * @param array $atts Shortcode attributes. |
| 32: | * |
| 33: | * @return false|string |
| 34: | * @since 1.0 |
| 35: | * @since 3.5 make sure meta_query in arg is defined as array, prior usage. |
| 36: | * @since 3.6 Runs on the [listing_advanced] engine (EPL_Shortcode_Listing), so it takes every [listing_advanced] option. Existing [listing] options give the same query and output as before. |
| 37: | */ |
| 38: | function epl_shortcode_listing_callback( $atts ) { |
| 39: | $shortcode = new EPL_Shortcode_Listing( $atts ); |
| 40: | |
| 41: | return $shortcode->render(); |
| 42: | } |
| 43: | add_shortcode( 'listing', 'epl_shortcode_listing_callback' ); |
| 44: | |
| 45: | /** |
| 46: | * Listing Shortcode Sorting |
| 47: | * |
| 48: | * @param array $sorters Array of sorters. |
| 49: | * |
| 50: | * @return array |
| 51: | * @since 1.0 |
| 52: | */ |
| 53: | function epl_sorting_options_callback( $sorters ) { |
| 54: | foreach ( $sorters as $key => &$sorter ) { |
| 55: | if ( 'status_asc' === $sorter['id'] || 'status_desc' === $sorter['id'] ) { |
| 56: | unset( $sorters[ $key ] ); |
| 57: | } |
| 58: | } |
| 59: | return $sorters; |
| 60: | } |
| 61: |