Support

Account

Home Forums General Issues Only searches by tag instead of by value

Unread

Only searches by tag instead of by value

  • I’m trying to search in an eligible sub-field in which there is a list of languages, to make it easier for the developers a label and a value has been put, but what I’m developing is only looking for the label, and what I want to achieve is that it looks for the value, instead of the label, or both, that is to say label and value

    
    <?php
    
    require_once("../wp-load.php");
    switch_to_blog(5);
    
    echo '<b>'.$_POST["BusquedaIdioma"].'</b>';
    
     // QUERY WP   
     
    // filter
    function my_posts_where( $where ) {
    	
    	$where = str_replace("key = 'idiomas_$", "key LIKE 'idiomas_%", $where);
    
    	return $where;
    }
    
    add_filter('posts_where', 'my_posts_where');
    
    $args = array(
        'post_type'              => array( 'profesiones' ),
        'posts_per_page'         => -1,
        'post_status'            => array( 'publish' ),
        'meta_key'               => 'nombre_profesion',
        'meta_query'             => array(
            array(
                    'relation'  => 'AND',
                    array(
                        'key'     =>  'idiomas_$_idioma',
                        'value'   =>  $_POST["BusquedaIdioma"],
                        'compare' => 'LIKE',
                    ),
                ),
        ),
        'orderby'    => 'meta_value',
        'order'     => 'ASC',
    );
    
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) : 
        echo '<table border="1" class="tablaDinamica">
        <thead>
            <tr>
                <th>Nombre de la profesion</th>
            </tr>
        </thead>
        <tbody>';
        while ( $query->have_posts() ) :
            $query->the_post();
           
            echo '<tr>
                    <td><a href="'.get_the_permalink().'">'.get_field('plural').'</a></td>
                </tr>';
             echo 'echo ';
        endwhile;
        echo '</tbody>
        </table>';
    endif;
    wp_reset_query();
    restore_current_blog();
    ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.