Skip to content

Commit

Permalink
updated - filters turned back on
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveJonesDev committed Oct 25, 2023
1 parent 41e5591 commit 145f55f
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,29 +347,29 @@ function npp_filter_post_object_query( $args, $field, $post_id ) {
add_filter( 'acf/fields/post_object/query', 'npp_filter_post_object_query', 10, 3 );

function modify_post_object_query( $args, $field, $post_id ) {
// Check if the parent block is 'acf/recommended-posts-block'
if ( isset($field['parent']) && $field['parent'] == 'block_acf/recommended-posts-block' ) {
// If there's a search term, modify the query to search by title only
if( isset($args['s']) ) {
// Set search term to a variable
$search_term = $args['s'];

// Modify the query
unset($args['s']); // Remove default search
$args['post_title_like'] = $search_term; // Add title search
}
}

// Return the modified arguments
return $args;
// Check if the parent block is 'acf/recommended-posts-block'
if ( isset($field['parent']) && $field['parent'] == 'block_acf/recommended-posts-block' ) {
// If there's a search term, modify the query to search by title only
if( isset($args['s']) ) {
// Set search term to a variable
$search_term = $args['s'];

// Modify the query
unset($args['s']); // Remove default search
$args['post_title_like'] = $search_term; // Add title search
}
}

// Return the modified arguments
return $args;
}
//add_filter('acf/fields/post_object/query', 'modify_post_object_query', 10, 3);
add_filter('acf/fields/post_object/query', 'modify_post_object_query', 10, 3);

function title_like_posts_where( $where, $wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get('post_title_like') ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
global $wpdb;
if ( $post_title_like = $wp_query->get('post_title_like') ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
}
//add_filter('posts_where', 'title_like_posts_where', 10, 2);
add_filter('posts_where', 'title_like_posts_where', 10, 2);

0 comments on commit 145f55f

Please sign in to comment.