AnonymousInactive
Hi Trevor,
In fact, i’ve a search.php file for my results. I wrote this code which appears on the top of the results :
global $searchandfilter;
global $post;
$author_id = $post->post_author;
$author = get_the_author_meta('display_name', $author_id);
$sf_current_query = $searchandfilter->get(802)->current_query();
$num_res = $wp_query->post_count;
echo $sf_current_query->get_field_string("_sft_category").'<br />';
echo $sf_current_query->get_field_string("_sft_thematique").'<br />';
if($num_res == 0) {
echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />';
}
echo 'Elément(s) trouvés(s): ' .$wp_query->found_posts;
I can display the author which is selected from the author select list but i don’t want to display anything if no author selected.
I need a valid snippet which might be :
if ($author_id != '0') {
echo $author.'<br />';
}
Thank you for your help.
Best regards.
AnonymousInactive
Hello Trevor,
What i meant : You give some snippets to display some informations like thais :
global $searchandfilter;
$sf_current_query = $searchandfilter->get(802)->current_query();
echo $sf_current_query->get_field_string("_sft_category").'<br />';
echo $sf_current_query->get_field_string("_sft_thematique").'<br />';
echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />';
echo 'Elément(s) trouvés(s): ' .$wp_query->found_posts;
I’d like to have a snippet to display the author chosen in my select list. If i try that code, it doesn’t work :
echo $sf_current_query->get_field_string("authors");
Is it possible to realize this ? It’s not in your documentation.
Thank you for your help.
Best regards.
Yup the form elements are there, but thats not the whole “field” as some fields contain multiple form elements (like ranges).
Again, this is coming in v3, a class you can use to build your own fields.
The problem with the current version of S&F is thats it poorly decoupled and got bloated.
Its grown over 3 years, had 1 major refactor, and its due for another.
You’ll have a very hard time to create your own fields on the fly, and its not something I can easily explain I’m afraid.
All I can say is, look at the display-shortcode file, which outputs the html of the fields (the function is called get_field
), that then relates to the others files you mentioned above (in the fields director), but you’ll have to figure out how so many other classes work, just because of poor decoupling.
Thanks
AnonymousInactive
Hi,
Just bought and read the docs but i’m not following here.
This is a piece from one template file in my theme:
<section id="events-lijst">
<?php
// the query
$options = array(
'post_type' => 'event',
'posts_per_page' => 20,
'order' => 'ASC',
'meta_key' => 'taal',
'meta_value' => 'Nederlands'
);
$query = new WP_Query( $options );
?>
<?php if ( $query->have_posts() ) : ?>
<div class="container">
<div class="eventrow">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
<div class="event-foto-sectie">
<?php $uitgelichte_afbeelding = get_field( 'uitgelichte_afbeelding' ); ?>
<?php if ( $uitgelichte_afbeelding ) { ?>
<a href="<?php the_permalink(); ?>"><img src="<?php echo $uitgelichte_afbeelding['url']; ?>" class="event-featured-img" alt="<?php echo $uitgelichte_afbeelding['alt']; ?>" /></a>
<?php } ?>
</div>
<div class="panel-body">
<?php
$dateformatstring = "l d F, Y";
$unixtimestamp = strtotime(get_field('datum'));
?>
<p><strong>Datum: </strong> <?php echo date_i18n($dateformatstring, $unixtimestamp); ?><br/><strong>Locatie: </strong><?php the_field( 'locatie' ); ?></p>
<span class="eventuitleg"><?php the_excerpt(); ?></span>
<p class="bekijkevent"><strong><a href="<?php the_permalink(); ?>">Bekijk dit evenement</a> >></strong></p>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<section class="section-padding">
<div class="container">
<div class="row-centered">
<div class="col-md-12 col-centered">
<strong>Sorry, geen enkel event geprogrammeerd op dit ogenblik...</strong>
</div>
</div>
</div>
</section>
<?php endif; ?>
</section><!-- event lijst -->
I want to put a row at the top where my query underneath is filterd on custom fields (using ACF)
AnonymousInactive
Hi,
I am trying to make a filter like this: http://i.imgur.com/3IU1LEU.png (they’re all just radio buttons and a range slider).
I have a page called “packages”. On that page I am listing all posts from the house_and_land custom post type. But honestly I’m not sure where to proceed form here.
I don’t need to use the search field, but instead when a user arrives at the “packages” page they will immediately see all the posts listed and the search filter next to it.
This is my code for listing all the house_and_land posts:
$args = array(
'posts_per_page' => 5,
'post_type' => 'house_and_land'
);
$properties_query = new WP_Query( $args );
if( $properties_query->have_posts() ):
while( $properties_query->have_posts() ) : $properties_query->the_post();
// Vars
$estate = get_field( 'estate' );
$home_area = get_field( 'home_area' );
$min_lot_width = get_field( 'min_lot_width' );
$storeys = get_field( 'storeys' );
$bed = get_field( 'bed' );
$bath = get_field( 'bath' );
$car = get_field( 'car' );
$price = get_field( 'price' );
?>
<li>
<a href="<?php echo the_permalink(); ?>">
<span class="estate"><?php echo get_the_title( $estate ); ?></span>
<span class="line-item estate min">Min lot width: <em><?php echo $min_lot_width; ?>m</em></span>
<span class="line-item estate area">Home area: <em><?php echo $home_area; ?>m<sup>2</sup></em></span>
<span class="line-item estate storeys">Storeys: <em><?php echo $storeys; ?></em></span>
<span class="line-item estate bed">Bed: <em><?php echo $bed; ?></em></span>
<span class="line-item estate bath">Bath: <em><?php echo $bath; ?></em></span>
<span class="line-item estate car">Car: <em><?php echo $car; ?></em></span>
<span class="price">From <em>$<?php echo $price; ?></em></span>
</a>
</li>
<?php
endwhile;
endif; wp_reset_query();
How do I get the search filters to work? As shown in the image (http://i.imgur.com/3IU1LEU.png) I need radio buttons for beds, baths, garages, storeys, and range sliders for price range and lot width. But the WP backend interface for S&F doesn’t make it obvious how to do that.
Thanks in advance.
If they are acf fields, then something like:
<?php echo get_field('field_name'); ?>
AnonymousInactive
function sf_filter_query_args( $query_args, $sfid ) {
if($sfid==1225){
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1225)->current_query();
$sf_current_query->get_field_string(“_sfm_event_archives”);
$_sfm_event_archives_array = $sf_current_query->get_array();
$archive_is_check = $_sfm_event_archives_array[_sfm_event_archives][active_terms][0][value];
//print_r($archive_is_check);
if($archive_is_check != ‘1’){
$args_custom = array(
“meta_key” => “imic_event_start_dt”,
“orderby” => “meta_value_num”,
“order” => “ASC”,
“meta_query” => Array (
“event_archives” => Array (
“key” => “event_archives”,
“value” => “0”
)
)
);
$query_args = array_merge($query_args, $args_custom);
}
// si aucun filtre d’appliqué
//if($sf_current_query->is_filtered()!=1){}
}
return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘sf_filter_query_args’, 100, 2 );
AnonymousInactive
Hi,
thanks for your help!!!
It wasn’t the wpml plugin,
but the custom code (that I was sure it wasn’t in cause)
I had to add the bold section here to make it work
function sf_filter_query_args( $query_args, $sfid ) {
if($sfid==1225){
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1225)->current_query();
$sf_current_query->get_field_string("_sfm_event_archives");
$_sfm_event_archives_array = $sf_current_query->get_array();
$archive_is_check = $_sfm_event_archives_array[_sfm_event_archives][active_terms][0][value];
//print_r($archive_is_check);
if($archive_is_check != '1'){
$args_custom = array(
<strong>"meta_key" => "imic_event_start_dt",
"orderby" => "meta_value_num",
"order" => "ASC",</strong>
"meta_query" => Array (
"event_archives" => Array (
"key" => "event_archives",
"value" => "0"
)
)
);
$query_args = array_merge($query_args, $args_custom);
}
// si aucun filtre d'appliqué
//if($sf_current_query->is_filtered()!=1){}
}
return $query_args;
}
add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 100, 2 );
Thanks again for your help guys!
Really nice plugin!
AnonymousInactive
Thanks for that! Got it working by testing for ($sf_current_query->get_field_string("_th_private_page_category")=="Page Categories: All Page Categories")
You can close this now, cheers.
AnonymousInactive
Hi Trevor,
My code:
<div id="results">
<?php query_posts($query_string . "&meta_key=premium&orderby=meta_value"); ?>
<?php while (have_posts() ) : the_post(); ?>
<div class="<?php
if (get_field('premium')) {
echo 'premium';
}
?> row-fluid padM marginDownS bRadiusM brightenCat resumenFicha">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<div class="col-md-4 col-sm-6 col-xs-2 erasePad">
<?php the_post_thumbnail( 'medium', array('class' => 'img-responsive bRadiusM')); ?>
</div>
<div class="col-md-8 col-sm-6 col-xs-10">
<h4 class="text-left secondColor textSizeM">
<?php if (in_category (array ('playas', 'municipios'))): ?>
<?php the_title(); ?>
<?php else: ?>
<?php the_title(); ?>
<?php endif ?>
</h4>
<p class="textSizeS mainColor esconder_xs">
<?php the_field('ciudad'); ?>
<?php the_field('cul_ciudad'); ?>
<?php the_field('en_municipio'); ?>
<?php the_field('rut_salida'); ?>
<?php the_field('pn_municipios'); ?>
</p>
<div class="esconder_xs">
<?php the_excerpt(array('class' => 'greyFont')); ?>
</div>
</div>
</a>
</div>
<?php endwhile;?>
<div id="pagination">
<?php wp_pagenavi( ); ?>
</div>
</div>
#results is set to “result container”.
And there are no javascripts errors… only two 404 getting a old image.
Thanks
rgds