Wednesday, September 21, 2022
HomeWordPress Developmentphp - Why is my array_diff utilization breaking issues?

php – Why is my array_diff utilization breaking issues?


On my WP web site, I often solely have one tag per publish.

Nevertheless, I now have some posts which have a second tag, “expired”, that I exploit for one more goal.

So I want to regulate my code beneath to take away that “expired” tag earlier than I course of the one tag left.

It appears like I ought to be capable to use array_diff to take away the “expired” tag, based mostly on my studying of php.internet and another stack trade posts.

Nevertheless, once I tried to implement that, I am getting this error: Deadly error: Uncaught Error: Object of sophistication WP_Term couldn’t be transformed to string

Are you able to present me the place I am going awrong right here? 🙂

//get matter (tag)
    world $publish;       
    $post_id = $post->ID;
    $entry_id = FrmDb::get_var( 'frm_items', array( 'post_id' => $post_id_here ), 'id' ); //get entry id
    $matter = get_the_tags($post_id); //get matter (tag) 

//this is what I am attempting so as to add

    $matter = array_diff($matter, ["expired"]); //take away expired tag if an expired publish

//
    $matter = $matter[0]->title; //ought to solely be one
    $topic_url = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $matter)));
    $image_id = get_post_thumbnail_id();
    $image_src = wp_get_attachment_image_src( $image_id, 'full' );
    $img_url = $image_src[0]; // picture url
        if (!empty($matter)) {
$see_more="<div id="matter"><a href="https://instance.com/matter/".$topic_url.'/">See extra from our '.$matter.'</a></div>';
        }
        else $see_more = "";

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments