Page and post loop same template
Use the_excerpt() instead of the_content() – the_content() will only cut off if you do it manually.
Use the_excerpt() instead of the_content() – the_content() will only cut off if you do it manually.
It’s still early for me, but you need to check for if( $events_query->have_posts() ) : rather than if( have_posts ) : as the latter will be checking against the current post type and not your custom query.
I realised that $wp_query doesn’t work for where I had customised the queries with WP_query. This is completely obvious I suppose when you know, but I didn’t, so here is the adjusted code in case it benefits some other amateur! Note that $media_query, $events_query etc are the instances of WP_query which I had created myself … Read more
You probably want to explode your list of page ID’s using the explode function. Something like; <?php $exmenuitems = explode(“,”,get_option(‘exmenuitems’)); $recentPosts = new WP_Query(); $recentPosts->query (array ( ‘post__not_in’ => $exmenuitems, ‘post_type’ => ‘page’, ‘showposts’ => $menuitems )); I’d recommend using the WordPress Menu building functions and admin interface. Its much more intuitive for end users … Read more
Seems like the easiest thing to do is to apply the tax query only if at least one “experience” term has been specified. Something like: // Get passed vars $experience = $_GET[‘experience’]; // Start building the args array $args = array( ‘post_type’ => ‘page’, ); // If any experience items were passed if( is_array( $experience … Read more
Codex has quite an extensive article on this – Displaying Posts Using a Custom Select Query. In a nutshell: // retrieve posts using our custom SQL (note that you should query * rather than pick fields) $posts = $wpdb->get_results($query, OBJECT); // this is global variable that WP functions rely on for output global $post; // … Read more
get_category_by_slug() returns a category object or FALSE: $cat1 = get_category_by_slug( ‘cata’ ); print ‘<pre>’ . htmlspecialchars( print_r( $cat1, TRUE ) ) . ‘</pre>’; Result: stdClass Object ( [term_id] => 3 [name] => Cat A [slug] => cata [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => category category__not_in and id values from variable => [parent] => … Read more
I fixed it by doing it a different way $query = new WP_Query(array( ‘post_type’ => ‘tracks’, ‘posts_per_page’ => -1, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘track_number’, ‘meta_query’ => array( array( ‘meta_key’ => ‘mixtape’, ‘meta_value’ => (string)$mixtape_id ) ) ));
Use rewind_posts() to reset a loop and run it multiple times: <?php $my_query = new WP_Query(‘cat=49&showposts=4&orderby=RAND’); ?> <div id=”carousel”> <?php while ($my_query->have_posts()) : $my_query->the_post(); // output each slide endwhile; ?> </div> <?php $my_query->rewind_posts(); ?> <ul id=”carousel-descriptions”> <?php while ($my_query->have_posts()) : $my_query->the_post(); // output each desc endwhile; ?> </ul> <?php $my_query->rewind_posts(); // etc.
Don’t stomp on the $wp_query global. Use your own variable to hold your query instead: $custom_query = new WP_Query( $args ); Then, you can use a little trick to fix pagination. Do this before the loop: global $wp_query; // Store it for safekeeping $temp_wp_query = $wp_query; // Now blank it out $wp_query = null; // … Read more