最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

filter custom field with checkboxes and show it with one shortcode

matteradmin6PV0评论

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 0
Add a comment  | 

1 Answer 1

Reset to default 0
add_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.

Post a comment

comment list (0)

  1. No comments so far