custom post types – Check that a slug is present in the get_terms request

Question


I want to give users the ability to create various custom post from the frontend, but depending on the assigned taxonomy, return the custom post form linked to it. So after having obtained the selected taxonomy, it is impossible for me to check if it exists in the get_terms() request.
I thougt it was because the in_array() function doesn’t do a great job when it is about multidimensional array. so I searched and find here a way to make another function that overcome that problem, but it stil doesn’t work.


Here’s my code:

<?php
    $cptTax = $_GET['choosetax'];

$tax1List = get_terms([
                        'taxonomy' => 'tax1',
                        'hide_empty' => false,
                    ]);

function in_array_r($needle, $haystack, $strict = false) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }
    return false;
}

if( in_array_r($cptTax, $tax1List, false)): ?>
<form action="action" method="post" enctype="multipart/form-data">

I checked the $tax1List variable with a var_dump() and the slug is there… but the function return false.
Thanks for your help

0
Emmanuel Toussaint 1 month 2021-08-19T19:28:09-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse