meta query - ACF repeater field with meta_query

admin2025-01-08  3

How can I use a repeater field with meta_query I have a repeater field with some text values only and have a form that sends variables to a page where I get the value and storage a value which is the VALUE in the meta_query, I want to get all the CPT that hast certain string in a repeater field for example:

if(isset($_GET['tecnology'])){
$tech = $_GET['tecnology'];
echo $tech;
}

if(isset($_GET['category'])){
    $cat = $_GET['category'];
    echo $cat;
}

if(isset($_GET['start'])){
    $star_point = $_GET['start'];
    echo $star_point;
}

$args = array(
    'post_type' => 'project',
    'posts_per_page' => -1,
    'orderby' => 'post_date',
    'meta_query' => array(

        array(

            'key' => 'tecnologies',
            'value' => $tech,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'category_project',
            'value' => $cat,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'route', //this is the repeater field
            'value' => $star_point, // this is the string I want to know if it´s in the repeater field
            'compare' => 'LIKE'
        )
    )
    );
  $loop_servicios = new WP_Query( $args ); 
?>

How can I use a repeater field with meta_query I have a repeater field with some text values only and have a form that sends variables to a page where I get the value and storage a value which is the VALUE in the meta_query, I want to get all the CPT that hast certain string in a repeater field for example:

if(isset($_GET['tecnology'])){
$tech = $_GET['tecnology'];
echo $tech;
}

if(isset($_GET['category'])){
    $cat = $_GET['category'];
    echo $cat;
}

if(isset($_GET['start'])){
    $star_point = $_GET['start'];
    echo $star_point;
}

$args = array(
    'post_type' => 'project',
    'posts_per_page' => -1,
    'orderby' => 'post_date',
    'meta_query' => array(

        array(

            'key' => 'tecnologies',
            'value' => $tech,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'category_project',
            'value' => $cat,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'route', //this is the repeater field
            'value' => $star_point, // this is the string I want to know if it´s in the repeater field
            'compare' => 'LIKE'
        )
    )
    );
  $loop_servicios = new WP_Query( $args ); 
?>
Share Improve this question edited Jan 20, 2020 at 5:39 Chetan Vaghela 2,3984 gold badges10 silver badges16 bronze badges asked Jan 17, 2020 at 19:43 kelvin ramirezkelvin ramirez 577 bronze badges 2
  • You should look up XSS and see how your code allows it. – Joel M Commented Jan 21, 2020 at 3:40
  • ok nvm i guess i can see ur not going to leave the echos there. – Joel M Commented Jan 21, 2020 at 3:41
Add a comment  | 

1 Answer 1

Reset to default 0

I don't think it's possible. ACF stores repeater data in separate postmeta fields - one database row for every field in the repeater - so you would have to query multiple fields, and unless you always have the same number of repeater fields, you wouldn't even know how many to query.

It sounds like you would be better off structuring your data a little more heavily by making custom taxonomies. Taxonomy queries are also much, much faster than meta queries, so performance will be much better.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736267432a1196.html

最新回复(0)