dqsk4643 2012-07-11 18:39
浏览 13
已采纳

无法让'get_the_title'在函数中工作

I've used this in other functions, but it doesn't seem to work in this particular one...

  <?php
      $page = get_the_title();
      $blogusers = get_users('orderby=display_name');
      foreach ($blogusers as $user) {
        $cpt_count = wpse31443_author_has_custom_post_type( $user->ID, $page );

        if (!empty($cpt_count)) {
          echo '<li>' . $user->display_name . '' . $cpt_count1 . '</li>';
        }
      }
    ?>

If I change $page = get_the_title(); to $page = 'title';then it works, so it's something with get_the_title(); but I'm not sure what because it has worked in other functions.

  • 写回答

2条回答 默认 最新

  • drlu11748 2012-07-11 19:08
    关注

    The most common reason why "get_the_title()" wont work is if it is not in "the loop". Make sure that you call the function from within the loop only. If called from elsewhere, you will need to pass the page/post id to the function.

    You'll get more information here: http://codex.wordpress.org/Function_Reference/get_the_title

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号