dongmu9253 2015-11-13 15:42
浏览 18

如何在函数中添加WordPress循环?

I want to add WordPress loop in function. I tried adding this code in function but it's not working. Using global $post; also not take any effect. Can anyone please tell me how to add loop in function?

Loop:

$term_lists = wp_get_post_terms($post->ID, 'vendors', array("fields" => "all"));

foreach($term_lists as $term_singles) {

echo $custotaxos = $term_singles->slug."<br>"; //do something here

$myposts = get_posts(array(
    'showposts' => -1,
    'post_type' => 'vendor',
    'tax_query' => array(
        array(
        'taxonomy' => 'vendors',
        'field' => 'slug',
        'terms' => array($term_singles->name))
    ))
);

foreach ($myposts as $mypost) {
      echo $mypost->post_title . '<br/>';
      echo  $mypost->ID . '<br/>';
echo get_permalink($mypost->ID);

echo "<br>";
}

}

Function:

function woo_custom_product_tab_content() {

}
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tab' );
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 单片机学习顺序问题!!
    • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
    • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
    • ¥15 相敏解调 matlab
    • ¥15 求lingo代码和思路
    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 如何绘制动力学系统的相图