Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter tatas09

    (@tatas09)

    Wow that is great vtxyzzy. Yesterday I find a workaround using Shortcodes and it adds more flexibility but I’m going to save that code for another time. Thank you!

    So I put this on my functions.php page

    function productos($atts, $content = null) {
        extract(shortcode_atts(array(
            "slug" => '',
            "query" => ''
        ), $atts));
        global $wp_query,$post;
        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query(array(
        'name'=> $slug,
        ));
        if(!empty($slug)){
            $query .= '&name='.$slug;
        }
        if(!empty($query)){
            $query .= $query;
        }
        $wp_query->query($query);
        ob_start();
        ?>
        <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
            <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
            <div><?php the_content() ?></div>
        <?php endwhile; ?>
    
        <?php $wp_query = null; $wp_query = $temp;
        $content = ob_get_contents();
        ob_end_clean();
        return $content;
    }
    add_shortcode("producto", "productos");

    And in my page template I just write [producto slug=”MY-SLUG”] and that way I can display multiple post just with the slugs. Hope someone find this useful.

Viewing 1 replies (of 1 total)