php – News only for certain group in wordpress

Question:

When inserting a post in wordpress, I have the taxonomy 'group' with terms 'pharmacies, grocery stores, snack bars…', which are the groups, as I already have clients for these groups. What I need is that, when logging in to have restricted access to the client area, wordpress checks if it has news for the group whose client is part of and, if so, shows it along with the posts specifically for the client.

To show news directed to the customer I already have, I just am not able to do this verification by groups.

/*
Eu tenho o ID do CLIENTE na $_GET.
Tenho que buscar os grupos que o cliente participa
Checar se algum desses grupos tem vinculo com a noticia
*/
$meta_query[] = array(
    'key' => 'clientes',
    'value' => $_GET['id'],
    'compare' => '='
);

$tax_query[] = array(
    'taxonomy' => 'grupo'
);

$args = array(
    array(
        'post_type' => 'noticias'
        ,'meta_query' => $meta_query
    )
);    

$tmp = new WP_Query($args);

if(!$tmp->have_posts()){
    echo 'não tem notícias no momento';
    return;
}

while ($tmp->have_posts()){
    $tmp->the_post(); 
    echo get_the_title().'<br>';
}

Note: The customer is entered in the 'customers' post_type. In this post_type I have the fields email, password and the groups are listed in the form of taxonomy to be able to link the client to the group.

Answer:

Wouldn't it be better for you to change the key to customer_grupo and its value would be the group belonging to the customer, as you are already passing the customer's id in the url, you would get it like this:

$group_client = get_post_meta( $_GET['id'], 'client_group', true );

                $type = 'noticias';
            $args=array(
                'post_type' => $type,
                'post_status' => 'publish',
                'posts_per_page' => -1,
                                    'meta_key'       => 'grupo',
                                    'meta_value'     => $grupo_cliente

            );
                           $tmp = new WP_Query($args);

           if(!$tmp->have_posts()){
              echo 'não tem notícias no momento';
             return;
           }

          while ($tmp->have_posts()){
            $tmp->the_post(); 
            echo get_the_title().'<br>';
          }
Scroll to Top
AllEscort