• Hi everyone,

    I’m working on an online shop (using TheCartPress plugin) and i’m trying to customize the loops.

    The plugin creates a custom taxonomy called tcp_product_category and inside that I have 3 groups, lets say cloths,shoes,reserved.
    Items that belongs to ‘Reserved’ should be visible only to registered users and shouldn’t appear in the loop if the user is not logged.

    Currently i’m using this code in loop:
    <?php if ( is_tax('tcp_product_category', 'reserved') && (!is_user_logged_in())) { echo 'hide product'; } else { echo 'do the normal loop'; ?>

    but its not working…I also tryed the $get_taxonomies() function:

    <?php
    $arg = array( 'name' => 'reserved' );
    $output = 'names';
    $categ = $get_taxonomies($arg,$output);
    if ($categ->name == 'reserved') && (!is_user_logged_in())) { echo 'hide product'; } else { echo 'do the normal loop'; ?>
    ?>

    but no luck in here too.. What i’m doing wrong ? Wich is the best way to do that ?

    Cheers
    Massimiliano

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter visualtricks

    (@visualtricks)

    Sorry to bump…i’m tryin to solve myself but I still could use some help.. ??
    Maybe i’m on the right direction though.. it turned out I’m not looking for a taxonomy term but for custom posts (belonging to custom taxonomy) that have a certain tag, so I think I should filter out these posts with query_posts() when user is not logged in. I got the tag ID by looking at the url in admin panel when I Edit the reserved product category (wp-admin/edit-tags.php?action=edit&taxonomy=tcp_product_category&tag_ID=8&post_type=tcp_product) so i’m putting this:
    if ( !is_user_logged_in() ) { query_posts( ‘taxonomy=tcp_product_category&tag__not_in=8&post_type=tcp_product’ ); }
    just before the loop starts but…reserved item still shows up..
    I’ve also tryed this

    if ( !is_user_logged_in() ) {
    
    	$args = array(
    			'tax_query' => array (
    						   'taxonomy' => 'tcp_product_category',
    						   'field' => 'slug',
    						   'terms' => 'areariservata',
    						   'operator' => 'NOT IN'
    						   ),
    
    			'post_type' => 'tcp_product'
    			);
    
    	query_posts( $args );
    	}

    but still no luck. Am I at least on the right way ? What am I doing wrong ?

    as usual, thanks again for any help
    Massimiliano

    Thread Starter visualtricks

    (@visualtricks)

    If you like you can see the page here: https://www.parentesiquadraoutlet.eu/wordpress/?page_id=23

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prevent custom-taxonomy items from being listed in loop’ is closed to new replies.