Skip Navigation

[Resolved] Custom Post type not visible after using access control

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1664297
Annotation 2020-06-16 112140.png

This ticket is the follow of the old ticket
https://toolset.com/forums/topic/access-control-where-user-is-replicated-as-post-with-relationship-to-post-types/

Adding contributor to the customers solves all the problem, but an unusual behavior is happening on the site.

I have a custom-post type from a third party plugin. I created a shortcode which would return all the posts according to the the query.

function archive_classes_public($atts){

  $atts = shortcode_atts(
      array(
         'limit' => '',
      ),
      $atts
  );

  $limited = $atts['limit'];

  if($limited != " " ) {
    $limit = $limited;
  }
  else {
   $limit = -1; 
  }

  date_default_timezone_set('Asia/Calcutta');

  $today = date("Y-m-d  H:i");
   $args = array(  
        'post_type' => 'zoom-meetings',
        'post_status' => 'publish', 
        'posts_per_page' => $limit,
        'meta_key'   => '_meeting_start_date',
        'orderby'    => 'meta_value',
        'order'      => 'ASC',
        'meta_query' => array(
            array(
                'key'     => '_meeting_start_date',
                'value' => $today,
                'compare' => '>',
                'type'    => 'datetime'
            ),
        ),
    );

    $loop = new WP_Query( $args ); 
    $total_cards = "";
    $content .= "<div class='class-wrapper'>";

    while ( $loop->have_posts() ) : $loop->the_post();
        $product_id = get_post_meta( get_the_ID(), "_vczapi_zoom_product_id" ,true );
        $content_of_product_card = render_class_from_product_id_public($product_id);
            if(gettype($content_of_product_card) == "string" ) {
            $total_cards .= $content_of_product_card;   
            }       
  endwhile;
      $content .= $total_cards;
      $content .= "</div>";
      if($total_cards == ""){
        $content .= "No Upcoming Classes Added. ";
      }

    wp_reset_postdata(); 
  return $content;

}
add_shortcode('archive_classes_public', 'archive_classes_public');

After I have started using Toolset access in the post type the code runs only at one place : hidden link and wont work on other hidden link locations. Only when the customer logs in with contributor role capabilities the query returns posts.

I have marked guest user to be able to read the post.
Screenshot attached.

#1664637

Hello,

The problem you mentioned above is abnormal, if you have enabled permission for guest users, then it should be able to output posts for guests, I suggest you check the compatibility issue first:
Deactivate all other plugins, and switch to wordpress default theme 2020, and test again

And Toolset Access plugin is using WordPress hook "posts_where" to apply the filters, you can also disable filters from Access plugin by adding a line in your custom PHP codes, for example, add change this line from:

        'order'      => 'ASC',

To:

        'order'      => 'ASC',
        'suppress_filters' => true,

More help:
https://developer.wordpress.org/reference/classes/wp_query/

@type bool $suppress_filters Whether to suppress filters. Default false.