Support

Account

Home Forums General Issues create a shortcode with filder for a field

Helping

create a shortcode with filder for a field

  • Hello,

    I need to create a shortcode to list all campers for a certain nummer of persons (f.e. all campers for 4 persons) which sould be choosable. The shortcode should be variable that it looks like this: [shortcode personen=”x”].

    I created a function to list all camper for 6 persons:

    function modell_nach_personenzahl_variabel() {

    $args = array(
    ‘post_type’ => ‘womos’,
    ‘order’ => ‘ASC’,
    ‘orderby’ => ‘personen’,
    ‘field’ => $atts[‘personen’],
    ‘numberposts’ => -1,
    ‘meta_query’ => array (
    array (
    ‘key’ => ‘personen’,
    ‘value’ => ‘6’
    )
    )
    );

    How do I have to change this to have the variable shortcode?
    thanks for the help.

  • add_shortcode( 'qg_shortcode', 'qg_shortcode' );
    function qg_shortcode() {
        $buffer = '<h3>Post Titles</h3>';
        $q = new WP_Query(array(
            'post_type' => 'post',
            'posts_per_page' => 5
        ));
        while ($q->have_posts()) {
            $q->the_post();
            $buffer = $buffer.get_the_title().'<br>';
        }
        wp_reset_postdata();
        return $buffer;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘create a shortcode with filder for a field’ is closed to new replies.