根据作者ID查询帖子

Tho*_*mas 0 php wordpress

我有当前的作者ID存储在$theauthorid我想基于作者ID进行查询所以我这样做

query_posts('author=$theauthorid');
Run Code Online (Sandbox Code Playgroud)

但是,除非我手动编写id,否则它不起作用.我知道id正确存储,因为当我回复它时,我得到了正确的id.

Mar*_*ijn 5

正确的方法是将变量置于引号之外.这样您就可以使用单引号或双引号.

query_posts( 'author=' . $theauthorid );