Tag Info

Hot answers tagged

3

I think instead of using PHP rand you're better off limiting ( if you need to ) using posts_per_page and then getting a random set using orderby => 'rand'. Full List of Ordering Parameters So if I were to edit your query it would look like this: $args = array( 'post_type' => 'attachment', 'meta_key' => 'on_front_page', 'meta_value' ...


3

You have a couple of issues with your code. You have to set your loop to your custom query. As it stands, it is set to the main query You must always reset postdata with all instances of WP_Query Your code should be something like this <?php $args = array('post_type' => 'textorial'); $query = new WP_Query( $args ); while ($query->have_posts() ...


2

What you are experiencing is quite normal and expected. This is one of the big reasons I always hammer on this point, never use custom queries to replace the main query on the home page or any type of archive page. They solve one issue but creates plenty other new ones Lets look at what you have and why you are getting these results: BASICS Although you ...


2

The main query runs before the template is loaded. WordPress knows what template to load based on the results of that query. If you want to insert an additional query into the content area, either create a shortcode, or add a filter on the_content and do your page check/query output there.


1

is_category() does this: (...) Checks if a Category archive page is being displayed. (...) One line below on the codex page you find: To test if a post is in a category use in_category(). So just use the latter.


1

The below is starting after you do your query: $slide_list = array(); if ( $slides->have_posts() ) { while ( $slides->have_posts() ) { Grab the next slide using next_post to grab it without stomping globals $slide = $slides->next_post(); $slide_id = $slide->ID; Your image title is your post title: $slide_title ...


1

You can make use of the the_content filters to apply markup to get_the_content() $content = get_the_content(); echo apply_filters( 'the_content', $content ); You'll need to do the same for get_the_title() where you would use the_title filters instead of the_content Just another note on your code, remember to reset each of your custom loops with ...


1

You can filter any WP query using pre_get_posts(). The (sometimes) tricky part is that it is run against all queries of WP so you need to pinpoint your query using WP conditionals (is_admin(), is_page(), is_archive(), etc... ). You'll find a few useful examples on that page, too.


1

You can do this in one loop without as custom query. A couple of clever functions should get you there So lets look at a solution. First things first. I would suggest to separate your code completely here for easiness of reading and organisation. Roll back the changes in content.php and use this template only for all other templates. Create a separate ...


1

Can someone please explain how "$posts" is used within the loop? It isn't. It returns the array of queried posts , but it is insignificant and not used at all: if you remove it than the code works the same: global $query_string; query_posts($query_string.'&cat=-9'); if (have_posts()) : while (have_posts()) : the_post(); ... endwhile; endif; ...



Only top voted, non community-wiki answers of a minimum length are eligible