What sort of “checking” do you want to do?
I just need to check if an airtable field is empty. If its empty I don’t want it to display a particular text.
Did you ever find a solution to this? I am using shortcodes and would really like to only display records when a certain field has some value. Not the empty ones.
Hi,
I did something like this to hide or display part of the page :
function hide_empty_bloc( $atts, $content = null ) {
$values = shortcode_atts( array(
‘field’ => ”,
), $atts );
$query = new AirpressQuery(“Séances”, “Exercices”);
$query->filterByFormula(“{Nom de la séance}=’Perte de poids – Niveau 1 Femme – Jour 1′”);
$nom = new AirpressCollection($query);
$bloc_a = $nom[0][$values[‘field’]];
if (!empty($bloc_a)) {
}
else {
$content=”;
}
return $content;
}
add_shortcode(‘hide_empty_bloc’, ‘hide_empty_bloc’);
How it works :
- This creates an enclosing shortcode, in my case [bloc_a][/bloc_a]
- if the field called “Bloc A” is empty, then nothing within the shortcode get displayed.
Hope it might help.
Woops sorry,
this wasn’t the right one.
Here it is :
function bloc_a( $attr, $content = null ) {
$bloc_a = do_shortcode( ‘[apr field=”Bloc A”]’ );
if (!empty($bloc_a)) {
}
else {
$content=”;
}
return $content;
}
add_shortcode(‘bloc_a’, ‘bloc_a’);
Add this to your function.php
I’m no expert, but this worked anyway…
This might be useful too if you have multiple fields to check :
function hide_empty( $atts, $content = null ) {
$values = shortcode_atts( array(
‘field’ => ”,
), $atts );
echo do_shortcode( ‘[apr_populate field=”‘.$values[‘field’].'” relatedTo=”Exercices”]’ );
$nom_exercice = do_shortcode( ‘[apr field=”‘.$values[‘field’].’|Nom de l\’exercice”]’ );
if (empty($nom_exercice)) {
$content=”;
}
return $content;
}
add_shortcode(‘hide_empty’, ‘hide_empty’);
This creates an enclosing shortcode [hide_empty field=”YOUR FIELD”] YOUR CONTENT [/hide_empty]
If “YOUR FIELD” is empty, then “YOUR CONTENT” won’t be displayed.
Well it might not be the best way to do it, but once again it worked for me…