Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single listing related listing template #1738

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions includes/model/Listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,33 +1201,22 @@ public function get_listing_types() {
}

public function get_current_listing_type() {
$listing_types = $this->get_listing_types();
$listing_type_count = count( $listing_types );

$current = !empty($listing_types) ? array_key_first( $listing_types ) : '';

if ( isset( $_REQUEST['directory_type'] ) ) {
$current = sanitize_text_field( wp_unslash( $_REQUEST['directory_type'] ) );
}
else if( $this->default_directory_type ) {
$current = $this->default_directory_type;
}
else {

foreach ( $listing_types as $id => $type ) {
$is_default = get_term_meta( $id, '_default', true );
if ( $is_default ) {
$current = $id;
break;
}
if ( is_singular( ATBDP_POST_TYPE ) ) {
$directory = get_post_meta( get_the_ID(), '_directory_type', true );
} else if ( ! empty( $_REQUEST['directory_type'] ) ) {
$directory = sanitize_text_field( wp_unslash( $_REQUEST['directory_type'] ) );

if ( ! is_numeric( $directory ) ) {
$directory_term = get_term_by( 'slug', $directory, ATBDP_DIRECTORY_TYPE );
$directory = $directory_term ? $directory_term->term_id : 0;
}
}

if( ! is_numeric( $current ) ) {
$term = get_term_by( 'slug', $current, ATBDP_TYPE );
$current = $term->term_id;

if ( ! empty( $directory ) && directorist_is_directory( $directory ) ) {
return (int) $directory;
}
return (int) $current;

return directorist_get_default_directory();
}

public function search_category_location_args() {
Expand Down