Support

Account

Forum Replies Created

  • *Update

    I managed to show only the checkbox with a value matching the ID of the current post with the following code:

    function my_acf_load_field( $field )
    {
        global $post;
    	$post_id = get_the_ID();
        $field['choices'] = array();
        wp_reset_query();
        $query = new WP_Query(array(
            'post_type' => 'projectsoverview',
            'orderby' => 'menu_order',
            'order' => 'ASC',
            'posts_per_page' => -1,
    		'tag' => $post_id
    	));
    	
        foreach($query->posts as $product_id=>$macthed_product){
                $choices[$macthed_product->ID] = $macthed_product->post_title;
        }
    	
        $field['choices'] = array();
    
        if( is_array($choices) )
        {
            foreach( $choices as $key=>$choice )
            {
                $field['choices'][$key] = $choice;
            }
        }
    	
         wp_reset_query();
        return $field;
    	
    }

    Now I am trying to modify the query to only return the checkboxes that are checked. Is there a parameter that I can use for that purpose? Or is there another way?

  • Eventually I solved the problem. I displayed the actors in dynamic views element (from dynamic.ooo) on a frontend page.

    I put the filter criteria like so: filter by these conditions field = relatie_test (user based relationship field) operator = LIKE value = user(ID)

    That did the trick for me.

  • Since i can’t update the question, I will clearify it more this way.

    I am trying to solve the following scenario in wp-admin:

    When an agent logins in he should only be able to see the actors that have a relation with him. In the post from an actor (post_type actor) I have a relationship field (named: your_agent) which shows all the agents (post_type talent-agents).

    The ID of the agents post is for example 1. The agent should only see the actors that selected his post. (post with ID 1)

    When the ID of the selected post in the relationship is equal to the one from the agents post. The talent agent that owns that post (current logged in agent), should see that actor.

    I updated the code to this:

    function current_user_related_posts($query)
    {
        if( is_user_logged_in() ) { // check if there is a logged in user 
         
            $user = wp_get_current_user(); // getting & setting the current user 
            $roles = ( array ) $user->roles; // obtaining the role 
         
            return $roles; // return the role for the current user 
         
        } else {
            return array(); // if there is no logged in user return empty array  
        }
        
        $args = array(
          'post_type' => 'actor',
          'post_status' => 'publish',
          'meta_query' => array(
            'relation' => 'AND',  
            array(
              'key' => 'talent-agents_id',
              'value' => $post_id,
              'compare' => '='
            ),
            array(
              'key' => 'your_agent',
              'value' => $post_id,
              'compare' => '='
            )
          ),
          'fields' => 'id, your_agent'
        );
        $query = new WP_Query( $args );
    
        if( current_user_can('install-plugins') ) {
            $query->the_post('actor');
        }
        return $query; 
    }
Viewing 3 posts - 1 through 3 (of 3 total)