Remove echo from shortcode

‘echo’ statement will not work in shortcode function. shortcode function is just returning the variable; So your code will be like this: if(get_field(‘group’)) { $html=””; $html.= “<ul class=”sponsors”><h2>” , get_the_title() , “</h2>”; while(has_sub_field(‘group’)) { $attachment_id = get_sub_field(‘image’); $size=”sponsorimage”; $image = wp_get_attachment_image_src( $attachment_id, $size , false ); $link = get_sub_field(‘link’); $html.= “<li>”; $html.= “<a href=”” , … Read more

Filter Posts from the Main Query

Untested: function custom_home_exclude( $where=”” ) { $exclude = array(); $newsQuery = new WP_Query (array( “post_type” => “news”, “meta_key” => “post_to_blog”, “meta_value” => 1, “meta_compare” => “!=”, “posts_per_page” => “-1″, )); while ($newsQuery->have_posts()) { $newsQuery->the_post(); array_push($exclude, get_the_ID()); } wp_reset_query(); $exclude = join(‘,’, $exclude); $where .= ” AND `ID` NOT IN ($exclude)”; return $where; } function custom_home_loop($query) … Read more

How to create a custom shortcode based on the layout?

You need to capture the attributes that passed to a shortcode. You can do that like this add_shortcode(‘testimonial’, ‘testimonial_shortcode_func’); function testimonial_shortcode_func( $atts ) { $atts = shortcode_atts( array( ‘style’ => ‘default_value_if_no_value_is_provided’, ), $atts ); if( $atts[‘style’] == ‘fancy’ ) { //do something } else if ( $atts[‘style’] == ‘something_else’ ) { //do something } //And … Read more

wp_query args adding muitiple tax_querys

You could use IF conditions to add the parameters, $args = array( ‘post_type’ => get_post_type(), ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1, ‘no_found_rows’ => true, ‘tax_query’ => array(), ); if(condition){ $args[‘tax_query’] = array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘product_category’, ‘field’ => ‘slug’, ‘terms’ => array($category->slug), //Supply the current product_category terms ), array( … Read more

Add posts to WP Query object

You can modify the query using the pre_get_posts hook, you will have to add the parameters of your query to the query provided by WordPress inside you callback function (exclude_category in the example below): Example from the WordPress Codex: function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-1,-1347’ ); … Read more