Skip to content

Commit

Permalink
Merge pull request #117 from JoryHogeveen/20-10-15-post_type-param
Browse files Browse the repository at this point in the history
Properly set post type param to fix issues with Polylang and possibly others.
  • Loading branch information
quasel committed Aug 17, 2022
2 parents 3c3ace5 + 03904bb commit c031d0a
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pods-beaver-themer.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ function pods_beaver_loop_before_query_settings( $settings ) {
*/
$field_params = apply_filters( 'pods_beaver_loop_settings_field_params', $field_params, $settings, $pod );

// Use post type wildcard by default.
$settings->post_type = 'any';

if ( $pod ) {
if ( $find_params ) {
// Optimized select only gets the ID
Expand All @@ -353,16 +356,26 @@ function pods_beaver_loop_before_query_settings( $settings ) {
$field_params['output'] = 'id';
$ids = $pod->field( $field_params );
}

// Add pod name as the post type query.
$settings->post_type = $pod->pod;
// Add pod context to the settings so other filters can make use of this.
$settings->pod = $pod;
// Add relationship context.
if ( 'pods_relation' === $settings->pods_source_type && ! empty( $settings->pods_source_relation ) ) {
$field = $pod->fields( $settings->pods_source_relation );
if ( $field && ! empty( $field->pick_val ) ) {
$settings->post_type = $field->pick_val;
$settings->rel_pod = pods( $field->pick_val );
}
}
}

if ( empty( $ids ) ) {
// No Fields found make sure the end result is an empty WP_Query
add_filter( 'fl_builder_loop_query', 'pods_beaver_empty_query' );
}

// we have id's no need to specify the type
$settings->post_type = 'any';

add_filter( 'fl_builder_loop_query_args', 'pods_beaver_uabb_blog_posts', 10, 1 );

$setting_post_type_ids_field_name = 'posts_' . $settings->post_type;
Expand Down Expand Up @@ -434,6 +447,14 @@ function pods_beaver_uabb_blog_posts( $args ) {
$args['post_type'] = 'any';
remove_filter( 'fl_builder_loop_query_args', 'pods_beaver_uabb_blog_posts' );

// Set post type correctly if a Pod is found.
$settings = pods_v( 'settings', $args, array() );
$pod = pods_v( 'pod', $settings, null );
$pod = pods_v( 'rel_pod', $settings, $pod ); // Field relationship.
if ( $pod ) {
$args['post_type'] = $pod->pod;
}

return $args;
}

Expand Down

0 comments on commit c031d0a

Please sign in to comment.