News only for a certain group in wordpress

6

When inserting a post in wordpress, I have the taxonomy 'group' with terms 'pharmacies, grocery stores, snack bars ...', which are the groups, since I already have clients for these groups. What I need is that, when you log in to have restricted access in the client area, wordpress checks to see if you have news for the group whose client is a part and, if so, show it along with the post specifically for the client. >

To show customer-targeted news I already have, I just can not do this group verification.

/*
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 client is inserted into the post_type 'clients'. In this post_type I have the fields email, password and groups are listed in the form of taxonomy to be able to link the client to the group.

    
asked by anonymous 21.02.2014 / 15:13

2 answers

1

It would not be better for you to change the key to client_client and its value would be the group belonging to the client, as you are already passing the client id in the url, it would look like this:

$ customer_group = get_post_meta ($ _GET ['id'], 'customer_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>';
          }
    
25.02.2014 / 22:24
0

I will assume that users (customers) by registering / registering in WordPress , choose the group they will be part of and will save a new user metadata to the database.

To retrieve this information that was entered during the registration, you will need to use the get_user_meta function, passing the metadata key, say for example you chose to call it user_group_info , you then retrieve the value of user_group_info , perform the necessary checks and finally try to get the posts according to user_group_info value.

25.02.2014 / 09:24