Tag Info

New answers tagged

0

I've answered my own question with some more reading and some messing around... I had to run a 'foreach' that cycles through the given post's comments within the main loop. The following code looks at all the comments for each post that passes through the loop and checks for a specific string in the comments' content. Depending on if $findme is matched, a ...


1

You are correct that this is ineffecient, and there isn't really much you can do about it. I think the only other way to do this may be is with a very large (also ineffecient ) custom SQL query which unfortuantely I cannot help you with. If you have like 10 or 20 terms, the impact will not be that big, but if you have more, the effect can get very ...


1

You may not need to pass in the_post(). Calling the_post() sets up the global $post object, and get_field() may also be accessing the global $post object


6

I guess you have: the_content(); wp_link_pages(); in your theme file. So you can instead try the following (PHP 5.4+): /** * Append the wp_link_pages to the content. */ ! is_admin() && add_filter( 'the_content', function( $content ) { if( in_the_loop() ) { $args = [ 'echo' => false ]; // <-- Adjust the arguments ...


0

Right now you have: if ( $latest->have_posts() ) { while ($latest->have_posts()) : $latest->the_post(); ?> ... inside the loop <?php endwhile; } Which in pseudocode is: if we have posts foreach post show the post endforeach endif So you need to do this instead: if we have posts open wrapper div foreach post ...


0

If I understand you correctly, you want to modify your code so it looks like this at the top: <div class="new_wrapper"> <?php $args = array( and this at the bottom: <?php endwhile; } ?> </div> <?php $v = array(); It sounds like you may have been adding the <div></div> inside the <?php ?> code, which would have ...


0

You should open div right before argsand <?php and close it right after endwhile, if I got question right.


1

Using the the_posts filter: Here's one idea using the the_posts filter, that fires before setup_postdata() is activated: /** * Replace [nextpage] with <!--nextpage--> through the 'the_posts' filter. * * @see http://wordpress.stackexchange.com/a/183980/26350 */ ! is_admin() && add_filter( 'the_posts', function( $posts ) { $posts = ...


0

This is strange and should not happen by default. get_posts uses WP_Query. If you look at the source code of get_posts, all the parameters passed to get_posts is passed unchanged to WP_Query except parameters like category which is changed to cat, the include and exclude parameters to include or exclude certain posts which is changed to post__in and ...


4

The issue, I believe, is that if ($stories) is always returning true, een if there are no posts. It's then looping through the WP-Query elements, not the actual posts. Try this instead: if ( $stories->have_posts() ) { while ( $stories->have_posts() ) : $stories->the_post(); echo get_the_title( get_the_ID() ); endwhile; ...


0

The strtotime() function is what you need here: $date = date( 'Y-m-d', strtotime( $date ) ); //2015-04-10 with your example Note that you will need to do this when you save those values, not when running the query. You can't convert data that's already in the database on the fly when running a query. Edit: I noticed an error in your meta query. This ...


0

In short, yes! $args = array( 'post_type' => 'summerartcamp', 'cat' => 15, //This is for the Morning Group - I'll have a second loop for the Afternoon Group 'order' => 'ASC', 'meta_key' => '_expiration-date', 'orderby' => 'meta_value' ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() /* Make sure ...


2

The function next_post_link() allow excludes, with the parameter excluded_terms. Add a list of the IDs of the password protected posts to this param. You get a list of all password protected posts with the follow example via DB select. $password_pages = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ...


0

Use pre_get_posts to add a meta query to the main query: function wpd_date_meta_query( $query ) { if( $query->is_post_type_archive( 'your_post_type' ) && $query->is_main_query() ){ $meta_query = array( array( 'key' => 'Date', 'value' => date('Ymd'), 'compare' => ...


0

So I actually solved this myself. Its not the most elegant solution, but it works. I figured it would help somebody. I first created a new post status using register_post_status() in functions.php. I then used pre_get_posts() also in functions.php, in which I filtered the main query on my archive page to only display posts of the status 'publish'. ...


2

As this is a presentational thing, I'd be inclined to use CSS (there are of course ways of doing it in PHP, and others may disagree.) You'd make use of the counter-reset and counter-increment properties. CSS counters can be applied to any element, not just ordered-lists (<ol></ol>) and added using pseudo-elements and you can control the ...


0

use wp_reset_query(); it will work.. <?php query_posts( 'post_type=posttype&p=302' ); if( have_posts() ) : while( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; endif; wp_reset_query(); ?> posttype can be "post" , "page" or your custom post type. Here p=302 is your post id.. Hope it will ...


0

Submitting a full blown answer now that we've figured it out. Transients can be hard to troubleshoot because if you save the wrong value to the database at first, you can be looking at an old—and bad—value, even if the code that sets your transient is now correct. The two ways you can fix this are to temporarily use delete_transient() or use a plugin ...


0

The loop in a page loads only the content of the page. Thus you see only one post. You have to set up a "Page of Posts". You can find basic examples in the codex at Page Templates. But using it as static front page results in some problems. The links to follow pages will not work. You have to evaluate get_query_var('page') instead of ...


1

You second approach (EDIT 2) is quite buggy and inefficient unfortunately. Also, you are not going to do this in one query. As I already stated, you need to look at the approach in this answer I have recently done. You were almost there in your first edit, the only problem is, you cannot do this in one query, you will have to do two, one to get the ...


0

Your syntax is slightly off - $episodes is an instance of WP_Query, not an array. If you want a full-blown loop for using all template tags, use: while ( $episodes->have_posts() ) { $episodes->the_post(); the_title(); // Episode title the_content(); // Episode content } wp_reset_postdata(); // Restore current episode Otherwise you can ...


0

Add this conditional statement in your custom function. if ( is_home() && get_query_var( 'paged' ) >= 2 )


0

Figured out a solution. Ended up querying each categories using "foreach" and inserting my custom function into the loop. Not sure if it's the best approach but I got it to work so eh. No one else seems to want to help.


0

You should clean it up some more but this will fix your code: <?php get_header(); ?> <div class="posts"><!-- BLOG --> <!-- Shapes on sides --> <div class="shapes_left"> </div> <div class="shapes_right"> </div> <?php if (is_tag()) { ?> <div id="archive_title"> ...


0

The correct iteration of the loop is: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> and ends here: <?php endwhile; else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> For more details on the loop see https://codex.wordpress.org/The_Loop Also I am not ...


0

This is the source of all your problems: <?php if(is_home() && !is_paged()) { ?> <?php query_posts(array('post__in'=>get_option('sticky_posts'))); ?> This takes the current query, and puts it to one side, and places a new query in its place. Here you're saying that you want to show the first page of sticky posts. You ...


0

You can get & list all categories, with sub-categories, like a "tree"! see solution: How to sort list of custom posts to get view like a tree of posts under categories and their children's categories?


1

Is there a reason to execute the query in each individual div instead of looping the div within the query? <?php $my_query = new WP_Query( 'post_type=portfolio&showposts=13' ); while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <div class="port1"> <?php the_title(); ?> </div> <?php endwhile; ?> ...


1

You could use in_array() with get_queried_object_id(): if( is_category() && in_array( get_queried_object_id(), $archive_categories ) ){ echo 'stuff'; } else { theme_loop(); }


2

I made a few adjustments. Once I created my two arrays, I combined them this way $merged_queries->posts = array_merge( $women->posts, $men->posts ); shuffle($merged_queries->posts); $merged_queries->post_count = $women->post_count + $men->post_count; while ( $merged_queries->have_posts() ) { $merged_queries->the_post(); // do ...



Top 50 recent answers are included