Problems with listing posts
-
Hello to all.
I have a question to the wp_query…
I want to create a shortcode that will display all posts in a category and the title begin with e.g. an A.Now all posts of the category will displayed. How can filter these posts out that not begin with an A?
Thanks to all in advance!!
CODE:
add_shortcode( 'list-posts', 'list_post_params_shortcode' ); function list_post_params_shortcode( $atts ) { ob_start(); extract( shortcode_atts( array ( 'type' => 'post', 'order' => 'ASC', 'orderby' => 'title', 'posts' => -1, 'category' => '', 'first_char' => 'A', ), $atts ) ); $options = array( 'post_type' => $type, 'order' => $order, 'orderby' => $orderby, 'posts_per_page' => $posts, 'category_name' => $category, 'first_char' => $first_char.'%', ); $query = new WP_Query( $options ); if ( $query->have_posts() ) { ?> <ul style="list-style-type:none; padding: 0px;"> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; wp_reset_postdata(); ?> </ul> <?php $myvariable = ob_get_clean(); return $myvariable; }
- The topic ‘Problems with listing posts’ is closed to new replies.