Ajax loop refresh on click

Shouldn’t be too tricky. First: create a javascript file and add this: jQuery(document).ready(function($){ $(‘#refresh-links-id’).click(function(e){ e.preventDefault(); $.post(ajaxurl,{action:’jpb_random_loop’}, function(data){ $(‘#content-inner’).fadeOut(250).empty().append( data ).fadeIn(250); }); }); }); Save that file in your theme directory somewhere (could be in a subdirectory too). For this to work, the refresh link should not be inside ul#content-inner. Pretty basic jQuery post call, though. … Read more

add_filter() doesn’t work in loop

It doesn’t work in your template because the query has already happened before the template is loaded. If you want to add your filter only under certain conditions, you need to hook an earlier action, like pre_get_posts, and check if the query is for the home page: function add_my_orderby_filter( $query ) { if ( $query->is_home … Read more

Dynamically excluding current page id

In your code, if $post_id were, say, 99, this: query_posts(“showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=”. $post_id .””); would result in this being passed to query posts: query_posts(“showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=”. 99 .””); so, your issue here is ‘. 99 .’ isn’t a valid value for exclude. That said, query_posts should only be used to alter the main loop in a template. if you … Read more

Why does this loop only work on the homepage?

If you look at that code carefully, the only thing it ever prints are sticky posts: if(is_sticky()) : ?> <div class=”slide”><a rel=”bookmark” href=”https://wordpress.stackexchange.com/questions/92193/<?php the_permalink() ?>”><?php echo the_post_thumbnail(‘full’); ?><h2><?php the_title(); ?></h2></a></div> <?php endif; You stand a better chance of having sticky posts on page 1 of the index than on any page thereafter. 404 pages don’t … Read more

Filtering posts by multiple taxonomies

First off, you should be using WP_Query vs query_posts. Have a look at the Taxonomy Parameters. Mainly tax_query and relation. // Repost from link above $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘movie_genre’, ‘field’ => ‘slug’, ‘terms’ => array( ‘action’, ‘comedy’ ) ), array( ‘taxonomy’ => ‘actor’, … Read more

How is WP_Query connected to WP_Post in The Loop?

Yes, an object containing other objects is “natural”. A House object contains an array of Furniture objects in its $furnitures property… Such as in our case… WP_Query contains an array of WP_Post objects in its $posts property… A one-to-many relationship. This is an Aggregation. OOP is all about programatically modelizing things. These things are: From … Read more

Looping through WP_Post Object

Based on what you said about a post being completed, you can check if its status is completed and if it is, then point to the title: foreach ( $lessons as $lesson ){ if( $lesson[‘status’] == ‘completed’ ){ echo $lesson[‘post’]->post_title; } }