数组中的条件语句

时间:2017-11-09 03:10:42

标签: php if-statement

我想在作者中添加条件语句。如果作者是管理员将此设置为null。这有可能吗?

$args = apply_filters( 'job_manager_get_dashboard_jobs_args', array(
    'post_type'           => 'job_listing',
    'post_status'         => array( 'publish', 'expired', 'pending' ),
    'ignore_sticky_posts' => 1,
    'posts_per_page'      => $posts_per_page,
    'offset'              => ( max( 1, get_query_var('paged') ) - 1 ) * $posts_per_page,
    'orderby'             => 'date',
    'order'               => 'desc',
    'author'              => get_current_user_id()
));

2 个答案:

答案 0 :(得分:3)

我认为get_current_user_id()正在为作者获取ID。

从此处更改您的代码:

'author' => get_current_user_id()

有了这个:

'author' => ((get_current_user_id() == 'admin') ? NULL : get_current_user_id())

答案 1 :(得分:0)

我认为您可以使用此示例代码。

<?php 
    $array = array('test' => testFunction());

    function testFunction()
    {
        // do your condition here
        // return 'a';
    }

    print_r($array);
?>
相关问题