Tag Info

New answers tagged

0

Your question is incomplete and you have omitted all the context for some weird reason. I hope we agree that query_posts() is a bad idea. There's enough been said on it: When to use WP_query(), query_posts() and pre_get_posts Having said that, have you tried wp_reset_postdata, wp_reset_query or rewind_posts? I have no idea what you are doing here, but you ...


2

Try to change: <?php if ( have_posts() ) To <?php if ( $verhuurd_query->have_posts() )


1

The function have_posts is for the main loop, so the if statement is checking the main loop, which will probably always have posts. You want to use the custom query's have_posts for the if statement instead. if ( $verhuurd_query->have_posts() ) : while ( $verhuurd_query->have_posts() ) : $verhuurd_query->the_post(); ?>


0

I'm not sure if this is exactly what you're looking for, but you might want to check out: get_attached_media() and wp_get_attachment_url().


0

Here is a solution I also used in the past. This allowed me to use the slides in other places on the page as well as in tiled galleries or thumbnails and so on. <?php $indicators = array(); $slides = array(); $counter = 0; while ( $loop->have_posts() ) : $counter++; array_push($indicators, '<li data-target="#testimonials" ...


1

You can use the condition <?php if($loop->post_count > 1){ /** * so show the carousel counter */ } ?>


1

If you don't define the field in the array then it defaults to ID. Your options are term_id, name and slug: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters 'tax_query' => array( array( 'taxonomy' => 'language', 'field' => 'name', 'terms' => get_the_title() ) )


0

here's the code which generate the right html. Maybe the code needs some improveme nts. <?php reqCrea = new WP_Query('category_name=creations'); //objet contenant les posts de la categorie creations $cptPosts = $reqCrea->post_count; //nombre de post ?> <?php //echo 'cptpost = ' . ...


1

You arent clear where you want your else statement, so Ive added one for each of the if's you included. <?php $post_type = 'post'; // <-- Post Type $tax = 'temporada'; // <-- Taxonomía $termino = get_terms($tax); $category = get_the_category(); $cat_name = $category[0]->cat_ID; if ($termino) { foreach ($termino ...


3

Query results for posts, terms, and metadata get placed in cache. If a function is called that accesses data from previously queried objects within the same request (or you're using a persistent cache mechanism that maintains data across requests), it will not trigger another query and will instead fetch the data from cache.


2

It seems like yes it depends whether it does create a new query or not. As Milo has pointed out in his answer, WordPress using a caching system. The function stack looks like this: get_the_permlink() calls get_permalink() calls get_post() which when given a post ID does this: $_post = WP_Post::get_instance( $post ); which looks like: /** * Retrieve ...


0

For the example you posted, the article is styled according to the css rule(s) for category-selling-and-advertising which is defined last (among the category-* classes) in the article's class attribute. You need to intercept the functionality of post_class() to change the order these classes appear. The post_class filter will do the job for you: ...


0

You can choose between simplicity and efficiency. Running a get_posts() with a meta query for every entry is the simplest approach, and will do the job. Of course, as you pointed out, there are performance considerations. If you are looking for a more efficient solution, you will have to dive as deep as the database layer and run your own SELECT query. ...


1

I figured it out: $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => "show_times_%_date", "value" => $this_month . "[0-9]{2}", "compare" => "REGEXP" ) ), ));


0

I believe all you need to do here is remove the day from your $this_month parameter and use the LIKE comparison (with a trailing %) to query the value - $this_month = date("Ym"); $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => ...


1

As I stated in comments, use pre_get_posts to alter the main query. Never replace the main query with a custom one. Again, from comments Just for starters, on each page load you are running the same query twice, it is slow, double the amount of db calls and pagination has to be tweaked to work almost 100 percent, this just to get the same posts :-) You ...


0

$args = array( 'post_type' => 'works', 'posts_per_page' => 40, 'meta_key' => 'wpcf-composition-date', 'orderby' => 'wpcf-composition-date', 'order' => "DESC", 'offset' => $offset, 'tax_query' => array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => ...


1

Give this a try. It replaces query_posts(), which you should never use (it kills unicorns) with WP_Query. Basically it first queries your sticky posts and then, if there were less than your required 3 posts, it will perform another query for the relavent number of posts. /** Grab the sticky post ID's */ $sticky = get_option('sticky_posts'); /** Query the ...


4

Move the control structure outside the template file and just put the repeatable markup and template tags inside. $event_query = new WP_query($args); if( $event_query->have_posts() ){ while( $event_query->have_posts() ){ $event_query->the_post(); get_template_part('loop', 'home'); } } wp_reset_postdata();


1

[Edit] If I understand correctly, what you call the "outer loop" is just for building a two-column layout. If so, you don't need to call two WordPress loops, just open a "fake" oeuvres at the beginning, close a "fake" oeuvres at the end, do a single loop (a single while have_posts()) and close and re-open an oeuvres DIV every 2 posts (when $iOeuvres%2 == ...


2

the_excerpt() is one of a few template tags that do not accept a post ID as a parameter. Instead, you need to set up the global $post, run your tags, then restore it: if ( $_post = get_post( 10 ) ) { setup_postdata( $post = $_post ); the_excerpt(); // Any other template tags for this post wp_reset_postdata(); }


0

I had to do this on a project years ago. Similar answer to djb, just with a bit more details. This will output all of your taxonomy names as an h3, with a bulleted list of each post title linked to their detail page. <?php // Output all Taxonomies names with their respective items $terms = get_terms('member_groups'); foreach( $terms as $term ): ?> ...


1

posts_per_page=-1 is perfectly fine. This is used to get all posts. As for your code, you should never ever use query_posts unless you want to intensionally break stuff on your pages. This is one of the most common functions used and yet the one function that causes the most problems in a website. I have recently done a post on custom queries and have ...


0

You can either run the loop, break after the first iteration, and then reset with rewind_posts(), or grab the ID for the first post & pass it to the appropriate template tags. Personally, I would opt for the latter: <?php if ( have_posts() ) : $post_id = $wp_query->posts[0]->ID ?> <header> <?php echo get_the_title( ...


0

All templates are build within the global scope, so you can access $wp_query, $post, get_queried_object() and get_queried_object_id() anywhere inside the template. As this is in the header, I will also use a conditional check like is_single() to specifically target the single page


0

Two thoughts: 1) Doesn't isotope have a method for adding "stuff"? 2) What about adding a custom field or two, to the product and then use those to create an element before / after that product? 3) Instead of injecting the message via the loop just create the div / wrapped with some - id or class - and then use jQuery to fill those with something random. ...


2

As Milo noted, the final result might look something like the following if ($wp_query->have_posts()) { while ($wp_query->have_posts()) { $wp_query->the_post(); $post_title = get_the_title(); # On the first pass, write the start of your single container if ( 0 == $wp_query->current_post ) { echo ...


0

From your query (noted in the comments above), the page you are looking at believes that it is your home page (e.g. your blog). Notice in the wp_query object the following [found_posts] => 8 [is_home] => 1 is_home signifies that it believes that it is showing the home page. If your files are set up as you say, you should check your admin panel ...


1

Once a fucntion has been hooked to an action, the function will be executed every time the action is called (with do_action). To stop this, the action should be removed. See remove_action: function do_entry() { if ( get_the_title() ) { add_action('loop_entry_before', 'function_that_adds_h2_structure'); } else { ...


0

Putting the answer I received via Twitter here for others to see: It was the sticky post under the Featured Comic section that was creating that phantom Untitled Article. So, by adding: 'post__in' => get_option( 'sticky_posts' ) to the arguments, it got rid of it. New code for the Featured Comic now looks like this: <?php $featured_comic_args = ...


-2

Try wp_reset_postdata() I'm pretty sure wp_reset_query() only works on the original global query.


3

slug is not a valid query paramter, so get_posts() will just return X latest posts! Use name instead. http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters


1

Based on the comments, you should be able to do something like the following: Create a custom taxonomy to hold your Temporadora items in (e.g. Temporadora 1) Create a custom post type to hold your episodes Create a relationship between the two From there, it should be a matter of doing something like the following: $args = array( 'orderby' => ...


1

You must use LIKE on the meta_key to support the SQL % pattern. The compare attribute only applies to the meta value. Instead you could try to filter it with: /** * Match any numbers in given a meta-key for WP_Query * * @see http://wordpress.stackexchange.com/a/177331/26350 */ ! is_admin() && add_filter( 'posts_where', function( $where ) { ...


0

Found the problem - i was using array, when i just needed to use such arguments: $args = array( 'post_type'=> 'post', 'paged' => $paged, 'posts_per_page' => 9, 'meta_key' => 'summary', 'meta_value' => $thesearch, 'meta_compare' => 'LIKE' ); Thanks for help guys.


0

Insert the post ID in the_field function. See the documentation. <?php the_field($field_name, $post_id); ?> $field_name: the name of the field to be retrieved. eg “page_content” (required) $post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc So in ...


0

You can either make use of get_children or get_posts or even WP_Query to get the the attached image ID's to the current post You can then use those ID's to gt the attached image with wp_get_attachment_image() Here is a basic idea that you can use in a widget or sidebar. (CAVEAT: Untested) $args = array( 'post_type' => 'attachment', ...


1

You need to add 'post_type' => array('post', 'opinion') to your $normal_args array and maybe remove the meta_query?. Are you sure you have any opinions with a _custom_blog_enhome of 1? Start from $normal_args = array( 'post_type' => 'opinions', 'post_status' => 'publish' ); and add arguments one by one and watch the results.


1

My suggestion would be to pass different arguments to Wp_Query Class. using 'cat' property, passing category Ids. <?php $custom_query = new WP_Query( array( 'cat' => '1,2,3,4' 'post_type' => 'my_post_type', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => ...


0

Since you are calling get_permalink() outside of the loop, you need to define the post $id parameter. You can access the post ID outside of the loop by invoking the global $post object and then referencing it's ID value. So your code would now look like this: <?php if ( ICL_LANGUAGE_CODE=='zh-hans' ) : global $post; $postid = $post->ID; ...


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.



Top 50 recent answers are included