How to display Common posts from specific Tag & Category with Shortcode

function common_cats($att){ $args = array( ‘category__and’ => $att[‘category’], //must use category id ‘tag__in’ => $att[‘tag’], //must use tag id for this field ‘posts_per_page’ => $att[‘posts_per_page’]); //get all posts $posts = get_posts($args); $output = “<ul>”; foreach ($posts as $post) : $output .= “<li>”.get_the_title(). “</li>”; endforeach; $output .= “</ul>”; return $output; } add_shortcode(‘commoncats’, ‘common_cats’); use [commoncats] where … Read more

Shortcode with a foreach and arguments

Here is your problem: foreach ($files[0] as $file) { There is no $files variable, so there is nothing to loop through. You can’t pull variables out of thin air and expect PHP to understand your intent. Computers are very literal, in the most extreme sense. They can’t intuit what you meant, or want. This code … Read more

How to exclude category ID from Looper in WordPress

The solution is already in your code: <?php foreach (get_categories( $args ) as $cat ) : ?> <a class=”categorylink” href=”<?php echo get_category_link($cat->term_id); ?>”><img src=”<?php echo z_taxonomy_image_url($cat->term_id); ?>” /> More specifically: <?php foreach (get_categories( $args ) as $cat ) : ?> …get_category_link($cat->term_id)… That term_id is the ID of the category, so just test if it matches … Read more

Missing image in gallery shortcode in custom feed

The problem was in additional symbols &#8221 in $attr[‘ids’] array. So I’ve changed: $atts[‘include’] = str_replace(array(“&#187;”,”&#8243;”,”&#8221;”), “”, $atts[‘include’]); $atts[‘orderby’] = str_replace(array(“&#187;”,”&#8243;”,”&#8221;”), “”, $atts[‘orderby’]); $atts[‘order’] = str_replace(array(“&#187;”,”&#8243;”,”&#8221;”), “”, $atts[‘order’]); $atts[‘exclude’] = str_replace(array(“&#187;”,”&#8243;”,”&#8221;”), “”, $atts[‘exclude’]); And now everything ok.

AddToAny shortcode in the loop

Alright, I got it. And it seems so obvious to me now, that I feel a little ashamed (I’m probably tired). I spent 2 days on this issue before realizing I made a big mistake. I used this jQuery to open the .sfr-share-box’ modal containing the share icons (with a full width overlay): $(‘.sfr-share’).on(‘click’, function() … Read more

How can i display gallery shortcode output under Post text

The do_shortcode() function returns the shortcode output as a string, which can be appenend to the post content with the_content filter. Here’s an example how to do that, // add filter with late priority add_filter(‘the_content’, ‘my_post_attachments_gallery’, 99); function my_post_attachments_gallery($content) { // modify only published posts if ( is_singular( ‘post’) && ‘publish’ === get_post_status() ) { … Read more