Hook to main query with filters based on custom fields

Have a look at the format of a meta_query in WP_Query. $meta_query = array( array( ‘key’ => ‘price’, ‘value’ => array( 500, 1000 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) ); $query->set( ‘meta_query’, $meta_query );

Modifying a Loop to Show More

Have you tried setting $count equal to 4 on line 8? Like this: <div class=”col”> <?php gab_dynamic_sidebar(‘Subnews1’);?> <?php $postnr = of_get_option(‘of_wn_nr8’) + of_get_option(‘of_wn_nr8a’); if (intval($postnr) > 0 ) { ?> <span class=”catname”><a href=”https://wordpress.stackexchange.com/questions/87543/<?php echo get_category_link(of_get_option(“of_wn_cat8′));?>”><?php echo get_cat_name(of_get_option(‘of_wn_cat8’)); ?></a></span> <?php $count = 4; // etc

new custom theme – posts displaying on top of one another

You have closed div having content class inside if statement which causes to break nested markup, instead close it outside if statement as following. <?php /* Template Name: Blog */ ?> <?php get_header();?> <div id=”blog-container”> <div class=”content”> <?php get_sidebar( ‘blog’);?> <?php if(have_posts()) : while(have_posts()) : the_post(”); ?> <div class=”meta”> <h3><a href=”https://wordpress.stackexchange.com/questions/89410/<?php the_permalink(); ?>”><?php the_title(); ?></h3> … Read more

Adding a featured image to a foreach WordPress loop

This is the syntax problem: $content .= ‘<img src=”‘.($post->the_post_thumbnail->small).'” />’; The the_post_thumbnail() function is not part of the $post object, and would print, rather than return, the post thumbnail, even if that method would work. Try using get_the_post_thumbnail() instead: $thumbnail = get_the_post_thumbnail( $post->ID, ‘small’ ); Note that this function returns the fully formed <img> tag … Read more

static page with multiple loops breaks post pagination

You aren’t setting the $paged variable, at least not in the code posted. Per the Codex, you need to do something like this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; … before trying to use the $paged variable. That is, it needs to come before this line: $wp_query->query(array(‘post_type’=>’post’,’post_status’=>’publish’,’showposts’>3,’paged’=>$paged)); Also, side note, what is this– php … Read more

Why is my category post repeating twice

You are calling a weird parameter in line 24 which i dont understand… did you copy paste this function from elsewhere? anyhow… change line 24 from: ‘$param_type’ => array($term->term_id), To this: ‘cat’ => array($term->term_id), Good luck and dont forget to read @toscho comment for future questions.

For Each +1 WordPress Loop

try yo use the build-in loop counter: <a data-slide-index=”<?php echo $wp_query->current_post; ?>” href=””><?php echo $imagethum; ?></a>

Video post format, extra content breaks video embed

If you don’t know what the content is, use a regular expression to test if there is an URL. Sample code: $content = get_the_content(); $pattern = ‘~([^”\’])?(https?://.*\.(flv|aac|mp4|mov|m4a|f4a|ogg|oga|mp3))([^”\’\?])?~i’; if ( preg_match( $pattern, $content, $matches ) ) { $parsedUrl = parse_url( $matches[ 0 ] ); // create the vidoe markup } else { // echo $content or … Read more

How to filter posts by category INSIDE the loop

Got a quite radical solution : function wpse_102497_modify_query_order( $query ) { if ( $query->is_main_query() ) { $query->set( ‘orderby’, ‘title’ ); } } add_action( ‘pre_get_posts’, ‘wpse_102497_modify_query_order’ ); Hope this will help.

Search page loop banner image issue

You have the header inside the Loop, so of course it prints once for each result. Put that outside the Loop proper. if (have_posts()) { ?> <img src=”https://wordpress.stackexchange.com/questions/102754/banner.jpg” /><?php while ( have_posts() ) { the_post(); // print contents } } Also, don’t use relative URLs in WordPress. You are in for all kinds of headache … Read more