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

Properly set post type param to fix issues with Polylang and possibly others. #109

Closed
Closed
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
17 changes: 14 additions & 3 deletions pods-beaver-themer.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,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 @@ -344,16 +347,18 @@ 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;
}

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 @@ -425,6 +430,12 @@ 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.
$pod = pods_v( 'pod', pods_v( 'settings', $args, array() ), null );
if ( $pod ) {
$args['post_type'] = $pod->pod;
}

return $args;
}

Expand Down