Registration Form Shortcode

do_action(‘register_form’); doesn’t echo the form. It runs inside the form. You can use it to add information or maybe alter some values… maybe. So the answer is that you can’t insert the registration form with that mechanism. And while there are function in wp-login.php, the form isn’t one of them. What you probably want is … Read more

do_shortcode within post query

You set $post_slug outside the Loop, so the value never changes. You need to reset that inside the Loop so that it will be reset to each post in turn as the Loop progresses. $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); $post_slug = $post->post_name; echo … Read more

Get post object in shortcode function

You need to reassign the $post yourself. See the WordPress Codex that setup_postdata won’t do it for you. Try this: global $post; $section_id = 16; $post = get_post( $section_id ); setup_postdata( $post ); the_content();

Shortcode inserts paragraphs before and after executing shortcode

I think this is the result of wpautop filter running on the_content. You can remove this filter from the content: remove_filter(‘the_content’, ‘wpautop’); // OR if the above line does not work: add_filter(‘the_content’, ‘remove_autop’, 1); function remove_autop($content) { remove_filter(current_filter(), ‘wpautop’); return $content; } Or you can use shortcode_unautop filter, but this will only work if your … Read more

Optimizing Query used for a Shortcode

I see a few things that you might try to shortcut things: Currently a Multisite network only allows one site ID, according to the Codex page for $wpdb->siteid. Also, the site ID is defined in your wp-config.php file as a constant, BLOG_ID_CURRENT_SITE. So any reference to $wpdb->siteid can be replaced by BLOG_ID_CURRENT_SITE. Look into the … Read more

Get custom post type list for every category shortcode

You are not dealing with categories. You are dealing with a custom taxonomy. $postlist_args = array( ‘posts_per_page’ => -1, ‘offset’ => 0, // ‘category’ => $category->cat_ID, // not this ‘tax_query’ => array( array( ‘taxonomy’ => ‘cars_category’, ‘field’ => ‘id’, ‘terms’ => $category->term_ID, ) ), ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘msccar’, ‘post_status’ => … Read more

How can I create a custom shortcode that will return a custom post type by ID?

Ok, I found a simple answer to my problem. This is the shortcode function I ended up using to get my desired result: function cpt_case_study_func($atts){ extract( shortcode_atts( array( ‘id’ => null, ), $atts ) ); $post = get_post($id); $content=”<div class=”case-study”><h3>” . $post->post_title . ‘</h3> <p>’ . $post->post_content . ‘</p></div>’; return $content; } add_shortcode(‘case_study’,’cpt_case_study_func’); Thanks to … Read more

Passing html tags as shortcode parameters

When I create shortcodes that accept html tags i only take the tag name, meaning that if the tag is <h3> then i ask the user to enter h3 and i add the <, </ and > in the shortcode handler ex: extract( shortcode_atts( array( ‘count’ => -1, ‘category_name’ => ”, ‘q_tag’ => ‘h3’, ‘orderby’ … Read more

Can I wrap an unordered list inside a shortcode?

You can capture the list in a variable, rather than echo it: $list=”<ul class=”strong”> <li>” . get_field( ‘highlights_list_item#1’ ) . ‘</li> <li>’ . get_field( ‘highlights_list_item#2’ ) . ‘</li> </ul>’; echo do_shortcode( ‘[one_half]’ . $list . ‘[/one_half]’ ); Note the use of get_field() rather than the_field(), which returns a custom field value as opposed to displaying … Read more