Hot answers tagged

5

You are returning inside your loop - so it returns on the first iteration, giving you one result only. You should build a string inside your loop instead, and only return when the loop is over. Something like $featured_properties = ''; if( $featured_query->have_posts() ): while( $featured_query->have_posts() ) : ...


3

This could be done in the template that displays your archive page when only one post is returned by wp_query for a given category. Something like this: if ( $wp_query->post_count == 1 && $wp_query->max_num_pages == 1 ) { wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); exit; }


3

FINAL EDIT From comments Unfortunately when I try method one, all links go back to the homepage As I stated, everything works on my test install. I actually forgot that your code works for you, because you have hardcoded the URL <a href='/?$tax=$slug' ><h5> $term->name </h5></a> What this tells me is that get_term_link() ...


3

I would prefer two array of images, captions. For example: I have added comments on the code for better understanding. function wpse216239_slider_shortcode( $atts , $content = null ) { // Attributes $atts = shortcode_atts( array( 'slides' => '', // one master attribute for slides 'captions' => '' // one ...


2

@setterGetter is right, you need to wrap it with do_shortcode() but you need to do it where the customizer field is called not inside the field within the customizer. In your case try looking in footer.php then if you're able to find where they output the code wrap it with echo do_shortcode() But that doesn't mean your shortcode will display properly, you ...


2

I think it's safe to say that wpautop() is a basket case without hurting anyone's feelings, but I wouldn't remove & add it at a different priority as that just makes things worse, as demonstrated (although what you posted is the browser trying to make sense of broken html, rather than the actual output, which does only have the <a> tag once). To ...


1

Here's another way to do it, utilizing get_template_part of wordpress function include_file($atts) { $a = shortcode_atts( array( 'slug' => 'NULL', ), $atts ); if($slug != 'NULL'){ ob_start(); get_template_part($a['slug']); return ob_get_clean(); } } add_shortcode('include', 'include_file'); ...


1

At first - do not use extract. It's very bad code style and is also depracated in core. Every time your foreach loop run, you override content of $output because you assign to this variable new content. What you want is to concatenate new list item with existing ones. This can be done using concatening assignment operator: $output .= '<li ...


1

You need to recurse into the shortcode content ($m[5] as returned by get_shortcode_regex()), the standard way being to use preg_replace_callback(): public function wrapShortcode( $content ) { $content = preg_replace_callback( '/' . get_shortcode_regex() . '/s', array( $this, 'wrapShortcodeCallback' ), $content ); remove_filter( ...


1

Or little bit simplier. function do_shortcode_only_for($content, $tagnames) { $pattern = get_shortcode_regex($tagnames); $content = preg_replace_callback("/$pattern/", 'do_shortcode_tag', $content); return $content; } Taken from original do_shortcode function.


1

You can not use a shortcode inside an attribute. You need to make a shortcode that will output the whole element.



Only top voted, non community-wiki answers of a minimum length are eligible