Query_post, get the taxonomy through the custom post field

0

Good morning, everyone. A page has a custom field with the name of a post_type. In query_post, I want to get the value that this field does not have the custom name (choose)

$ choice is the value that I get in the custom field.

I do not know if you can understand my question, but I thank you for any help.

    
asked by anonymous 12.06.2017 / 11:29

2 answers

2

If I understand your question, because it is very strange, it seems that you want to retrieve the value of the meta field, for that, the following code would suffice.

<!-- Quando está dentro do loop de posts e possui o post alimentado corretamente -->
<?php $escolha = get_post_meta( get_the_ID(), 'escolha', true ); ?>


<!-- Quando está fora do Loop ou precisa passar o ID manualmente -->
<?php $escolha = get_post_meta( "ID_DO_POST", 'escolha', true ); ?>

If you want to redeem all meta fields, you can hide the field, so WordPress will return all of them.

<!-- Caso não esteja dentro do Loop, passe o ID do post no lugar de get_the_ID() -->
<?php $metas = get_post_meta( get_the_ID() ); ?>

Now, if you want to redeem all posts with a certain meta field and a certain value:

$args = array(
   'meta_query' => array(
       array(
           'key' => 'escolha',
           'value' => 'valor_do_seu_meta_campo',
           'compare' => '=',
       )
   )
);

$query = new WP_Query($args);

With the category name in hand, you can redeem the posts as follows:

$category = get_post_meta($post->ID, 'escolha', true);

$query = new WP_Query(
    array(
        'category_name'  => $category,
        'orderby'        => 'title',
        'posts_per_page' => 3,
    )
);
    
12.06.2017 / 14:34
0

Instead of having at the beginning (') should have (")

query_posts("$category=categoria-todas-familia & showposts= -1 &showposts= 3 & orderby=title")
    
12.06.2017 / 19:29