The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
-
AuthorSearch Results
-
September 18, 2023 at 9:27 am #276863
PauParticipantHowdy Trevor!
Instead of a range date picker, we’re gonna go with only one date picker.
The thing is we need to query from that date in advance, so we did with this code.
function filter_query_args( $query_args, $sfid ) { // Trainings Form ID. if( 1788 === $sfid && ! empty( $_GET['_sfm_start_date'] ) ) { $year = substr( $_GET['_sfm_start_date'], 4, 4 ); $month = substr( $_GET['_sfm_start_date'], 2, 2 ); $day = substr( $_GET['_sfm_start_date'], 0, 2 ); $fdate = $year . $month . $day; $query_args['posts_per_page'] = -1; $query_args['orderby'] = 'meta_value_num'; $query_args['meta_key'] = 'start_date'; $query_args['meta_value'] = $fdate; $query_args['meta_compare'] = '>='; $query_args['meta_query'] = [[ 'key' => 'start_date', 'value' => $fdate, 'compare' => '>', ]]; /*$q = new WP_Query( $query_args ); print '<pre><br><br>'; //print $fdate . '<br>'; print count( $q->posts ) . '<br>'; //print_r( $query_args ); //print_r( new WP_Query( $query_args ) ); foreach( $q->posts as $p ) print get_post_meta( $p->ID, 'start_date', true ) . ' : ' . $p->post_title . '<br>'; print '</pre>';*/ } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_query_args', 99, 2 );
We’ve modified the query correctly, or that says the debug (as you can see commented in the code). The data is there, but somehow the results are not showing.
Any hints? Thanks in advance.
December 7, 2022 at 11:03 am #276695In reply to: Custom WP Query & offset parameter
Andrea FischerParticipantWhy not use the Edit Query Arguments Filter?
https://searchandfilter.com/documentation/action-filter-reference/
/////////////////
function filter_function_name( $query_args, $sfid ) {
if($sfid==12345)
{
//modify $query_args here before returning it
//$query_args[‘somearg’] = ‘newvalue’;
$query_args[‘offset’] = ‘1’;
}
return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );April 21, 2022 at 5:07 pm #276548In reply to: Exclude first post
Pou LalaParticipantSorry for the bad writing:
function sf_filter_query_args( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==31940) { //modify $query_args here before returning it //only show results within categories with these IDs $query_args['offset'] = '1'; } return $query_args; } add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 10, 2 );
April 21, 2022 at 5:07 pm #276546In reply to: Exclude first post
Pou LalaParticipantHi, I’ve a solution for that. You have to use the ‘offset’ parameter.
I added this to function.php:
<?php
function sf_filter_query_args( $query_args, $sfid ) {//if search form ID = 225, the do something with this query
if($sfid==31940)
{
//modify $query_args here before returning it
//only show results within categories with these IDs
$query_args['offset'] = '1';
}
return $query_args;
}
add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 10, 2 );
?>February 9, 2021 at 4:52 pm #275584In reply to: Editing query arguments
Ariane WeiselParticipantSure. So I want the results here to display the same as the taxonomy archive page.
Here is the pre_get_post that results in the taxonomy archive page.
// Order posts first by event and date, then by other kinds of content function order_events_by_event_date($query=false) { // only used on main query on front end of site if (is_admin() || !$query || !$query->is_main_query()) { return; } // modfiy a custom post type to show and order by meta value if (is_tax() || is_archive() ) { $query->set('orderby', array( 'meta_value' => 'DESC' ) ); $query->set('order', 'ASC'); $query->set('posts_per_page', -1); $meta_query = array( 'relation' => 'OR', array( 'key' => 'expired', 'compare' => 'NOT EXISTS', ), array( 'relation' => 'OR', array( 'key' => 'expired', 'value' => '0', ), array( 'key' => 'expired', 'value' => '1', 'compare' => '!=', ), ), ); $query->set('meta_query', $meta_query); } } // end function blunt_pre_get_posts add_action('pre_get_posts', 'order_events_by_event_date');
The nested array is necessary to include the “experiences” post type (first OR) and the array beneath it includes items that are not expired or field expired is empty.
I changed it using the code you provided above, removing the is_tax and first qualifiers about queries, and got the results posted above.
Only thing that seems to semi-sort the results is the sfid filter, so what is displaying results now is
function exclude_expired_results ( $query_args, $sfid ) { //if search form ID = 3988, the do something with this query if($sfid==3988) { //modify $query_args here before returning it $query_args['meta_query'] = array( 'orderby' => array( 'meta_value' => 'DESC' ), 'order' => 'ASC', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'expired', 'compare' => 'NOT EXISTS', ), array( 'relation' => 'OR', array( 'key' => 'expired', 'value' => '0', ), array( 'key' => 'expired', 'value' => '1', 'compare' => '!=', ), ), ), ); // end meta_query addtion to arg } return $query_args; } add_filter( 'sf_edit_query_args', 'exclude_expired_results', 20, 2 );
sfid is 3988. Thank you for any help.
February 4, 2021 at 7:04 pm #275335In reply to: Editing query arguments
Ariane WeiselParticipantThis reply has been marked as private.February 2, 2021 at 6:28 pm #275129In reply to: Display results not showing “draft” status products
Carmelo ArancioParticipantThis reply has been marked as private.February 1, 2021 at 7:19 pm #274881Topic: Editing query arguments
in forum Search & Filter Pro
Ariane WeiselParticipantHi there,
I’m trying to edit the query args to exclude posts with acf field that denotes the “event” post type is “expired” (true/false field). I’ve followed the example in the docs here …. but no dice. Not sure about the ‘somearg’ bit in your example, it is unexplained in the docs, could that be it? Many thanks in advance for having a look.function exclude_expired_results ( $query_args, $sfid ) { //if search form ID = 3988, the do something with this query if($sfid==3988) { //modify $query_args here before returning it $query_args['somearg'] = array( 'meta_query' => array( 'relation' => 'OR', array ( 'key' => 'expired', 'compare' => 'NOT EXISTS' ), array ( 'key' => 'expired', 'value' => '1', 'compare' => '!=' ) ) // end meta_query ); // end $args } return $query_args; } add_filter( 'sf_edit_query_args', 'exclude_expired_results', 20, 2 );
January 21, 2021 at 7:46 am #273454
Samuel SchneiderParticipantThis reply has been marked as private.January 12, 2021 at 4:03 pm #272540In reply to: Limiting media search to just PDFs
TrevorModeratorThis reply has been marked as private. -
AuthorSearch Results