I have a custom field with checkboxes. I created a code to show post-typs filtered by checkbox value with shortcodes e.g. [bettenaert-Querbett]
. The code works but do not look nice.
if ($i = 'Querbett') {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
if ( $i = 'Alkovenbett' ) {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
if ( $i = 'Queensbett') {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
if ( $i = 'Hubbett') {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
Is there any way to make the value variable, to have only one if-function or can I do it in an other way? Has anyone an idea and can help me?
I have a custom field with checkboxes. I created a code to show post-typs filtered by checkbox value with shortcodes e.g. [bettenaert-Querbett]
. The code works but do not look nice.
if ($i = 'Querbett') {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
if ( $i = 'Alkovenbett' ) {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
if ( $i = 'Queensbett') {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
if ( $i = 'Hubbett') {
add_shortcode( "bettenaert-{$i}", function() use ( $i ) {
modell_nach_bettenart_2( $i );
} );
}
Is there any way to make the value variable, to have only one if-function or can I do it in an other way? Has anyone an idea and can help me?
Share Improve this question edited Apr 13, 2019 at 18:12 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Apr 13, 2019 at 13:22 kuh13kuh13 51 bronze badge 01 Answer
Reset to default 0add_shortcode( "Querbett", "bettenaert");
add_shortcode( "Alkovenbett", "bettenaert");
add_shortcode( "Queensbett", "bettenaert");
add_shortcode( "Hubbett", "bettenaert");
function bettenaert ( $atts, $content = null, $tag ) {
modell_nach_bettenart_2( $tag );
}
Now use shortcode [Querbett]
, [Alkovenbett]
, [Queensbett]
or[Hubbett]
as required.
I hope this may help.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745592822a4634932.html
评论列表(0条)