I am importing fields from a Real Estate site.
The Import of one Custom Field looks like this…
Field Name after Import —> assistedLiving
Field Value —> false
to output the display in wordpress i use this…
<?php
global $wp_query;
$postid = $wp_query->post->ID;
if ($immopress_property['assistedLiving']): ?>
<li class="assistedLiving">
<span class="attribute" style="width:200px;display:block;float:left;"><?php echo 'Seniorengerechtes Wohnen' ; ?><span class="wpp_colon">:</span></span>
<span class="value"><?php echo get_post_meta($post->ID, 'assistedLiving' , true); ?> </span>
</li>
<?php wp_reset_query(); ?>
<?php endif; ?>
The Result on Site looks so…
**Seniorengerechtes Wohnen:false**
How can i display False/True Values to display Yes/No or in German Ja/NEIN?
The Funktion to display all Field (Display it Right with yes/no):
function immopress_the_fields( $args ) {
global $post, $ImmoPress;
extract( wp_parse_args( $args, array (
'id' => $post->ID,
'exclude' => $exclude,
'echo' => TRUE
) ), EXTR_SKIP );
$fields = immopress_get_fields( $args );
if ( !$fields )
return false;
$output = '';
$output .= '<ul class="immopress-fields">';
foreach ( $fields as $key => $value) {
$entry = $ImmoPress->values[$value];
if ( $entry == '')
$entry = $value;
$output .= "<li class='immopress-field-$key'>";
$output .= "<strong class='immopress-key'>{$ImmoPress->fields[$key]}: </strong>";
$output .= "<span class='immopress-value'>$entry</span>";
$output .= "</li>";
}
$output .= '</ul>';
if ( $echo ) {
echo $output;
} else {
return $output;
}
But i need to display only Single Name & Values not all importet fields.
Code for the Shortcode..
function immopress_fields_shortcode( $atts ) {
$args = wp_parse_args( $atts, array (
'echo' => FALSE
) );
return immopress_the_fields( $args );
}
add_shortcode( 'immopress_fields', 'immopress_fields_shortcode' );
Hope someone can Help me with that.
Thanks
Tony
How about if you simply use if / else statement like this:
Note:
For the code above to work,values for assistedLiving must use true/false and not 1 or 0.
Update
This is my first attempt at modifying shortcodes, so I’m not sure if it will work.
I’m also not sure if this is what you need:) – I modified it in a way so that you can specify a parameter fieldname and when used it should show only that field.
Change your shortcode function to this:
In function immopress_the_fields() after
add this:
Not that this code is not efficient since $fields gets filled with all the fields all the time. Modified code is just a workaround.
I recommend learning Smarty and then your code will be:
To create this output: