最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - How to filter specific element of an array in wordpressphp?

matteradmin5PV0评论

I have a php code as shown below in which I have added Line#A for the debugging purpose.

<div class="vidlist-main__meta cf">
    <?php

    //if ( has_excerpt() ) {the_excerpt();}
    $tags = get_the_tags( get_the_ID() );
    $cats = wp_get_post_categories( get_the_ID() );                // Line#Z
    echo '<pre>'; print_r($cats); echo '</pre>';                  // Line#A
    if ( $tags || $cats  ) : ?>    // Line#B
        <span class="archive-links">
            <?php
            \CPAC\Episodes\generate_markup_for_categories( $cats );    // Line#C
            \CPAC\Episodes\generate_markup_for_tags( $tags );          // Line#D
            ?>
        </span>
    <?php endif;?>
</div>

On adding Line#A, I get the following o/p at different cases:

Case A:

Array
(
    [0] => 13085
    [1] => 13093
)

Case B:

Array
(
    [0] => 1
    [1] => 13087
)

Case C:

Array
(
    [0] => 1
    [1] => 13085
)

Problem Statement:

I am wondering what code I need to add after Line#Z or at Line#Z so that Line#Z takes only [1]=>13093.

Post a comment

comment list (0)

  1. No comments so far