admin管理员组文章数量:1130349
I am New To Wordpress Plugin Development. I want to Create Short Code using Custom Post Type Method
function baztag_func( $atts, $content = "" ) {
return "content = $content";
}
add_shortcode( 'baztag', 'baztag_func' );
I am New To Wordpress Plugin Development. I want to Create Short Code using Custom Post Type Method
function baztag_func( $atts, $content = "" ) {
return "content = $content";
}
add_shortcode( 'baztag', 'baztag_func' );
Share
Improve this question
edited Oct 26, 2018 at 6:28
Pratik Patel
1,1091 gold badge11 silver badges23 bronze badges
asked Oct 26, 2018 at 4:53
RagupathiRagupathi
1012 bronze badges
9
- Sorry! But not getting you. What exactly want you ? – Pratik Patel Commented Oct 26, 2018 at 6:09
- [contact-form-7 id="11" title="Contact form 1"] – Ragupathi Commented Oct 26, 2018 at 6:28
- create short code like this – Ragupathi Commented Oct 26, 2018 at 6:28
- but i want use cusome post type – Ragupathi Commented Oct 26, 2018 at 6:29
- You want custom post type posts listing ,using shortcode right ? – Pratik Patel Commented Oct 26, 2018 at 6:30
1 Answer
Reset to default 1Try this
/**
* Register all shortcodes
*
* @return null
*/
function register_shortcodes() {
add_shortcode( 'listing', 'shortcode_mostra_produtos' );
}
add_action( 'init', 'register_shortcodes' );
/**
* Produtos Shortcode Callback
*
* @param Array $atts
*
* @return string
*/
function shortcode_mostra_produtos( $atts ) {
global $wp_query,
$post;
$atts = shortcode_atts( array(
'type' => ''
), $atts );
$loop = new WP_Query( array(
'posts_per_page' => '-1',
'post_type' => $atts['type']
) );
if( ! $loop->have_posts() ) {
return false;
}
while( $loop->have_posts() ) {
$loop->the_post();
echo the_title();
// DO YOUR HTML STUFF HERE
}
wp_reset_postdata();
}
Use short-code like:
[listing type="YOUR CUSTOM POST TYPE HERE"]
Please try and let me know if any query
Thanks!
I am New To Wordpress Plugin Development. I want to Create Short Code using Custom Post Type Method
function baztag_func( $atts, $content = "" ) {
return "content = $content";
}
add_shortcode( 'baztag', 'baztag_func' );
I am New To Wordpress Plugin Development. I want to Create Short Code using Custom Post Type Method
function baztag_func( $atts, $content = "" ) {
return "content = $content";
}
add_shortcode( 'baztag', 'baztag_func' );
Share
Improve this question
edited Oct 26, 2018 at 6:28
Pratik Patel
1,1091 gold badge11 silver badges23 bronze badges
asked Oct 26, 2018 at 4:53
RagupathiRagupathi
1012 bronze badges
9
- Sorry! But not getting you. What exactly want you ? – Pratik Patel Commented Oct 26, 2018 at 6:09
- [contact-form-7 id="11" title="Contact form 1"] – Ragupathi Commented Oct 26, 2018 at 6:28
- create short code like this – Ragupathi Commented Oct 26, 2018 at 6:28
- but i want use cusome post type – Ragupathi Commented Oct 26, 2018 at 6:29
- You want custom post type posts listing ,using shortcode right ? – Pratik Patel Commented Oct 26, 2018 at 6:30
1 Answer
Reset to default 1Try this
/**
* Register all shortcodes
*
* @return null
*/
function register_shortcodes() {
add_shortcode( 'listing', 'shortcode_mostra_produtos' );
}
add_action( 'init', 'register_shortcodes' );
/**
* Produtos Shortcode Callback
*
* @param Array $atts
*
* @return string
*/
function shortcode_mostra_produtos( $atts ) {
global $wp_query,
$post;
$atts = shortcode_atts( array(
'type' => ''
), $atts );
$loop = new WP_Query( array(
'posts_per_page' => '-1',
'post_type' => $atts['type']
) );
if( ! $loop->have_posts() ) {
return false;
}
while( $loop->have_posts() ) {
$loop->the_post();
echo the_title();
// DO YOUR HTML STUFF HERE
}
wp_reset_postdata();
}
Use short-code like:
[listing type="YOUR CUSTOM POST TYPE HERE"]
Please try and let me know if any query
Thanks!
本文标签: pluginsHow to Create Short Code Using Custom Post type
版权声明:本文标题:plugins - How to Create Short Code Using Custom Post type 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749231122a2336503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论