Tagged: 

Viewing 2 reply threads
  • Author
    Posts
    • #7292
      luxdelux
      Participant

      Howdy. Been testing relationship fields and have stumbled a bit.

      Use case:

      I’ve got a custom post type ‘workshop’ and I made the posts available on the user edit screen as a relationship which works:

      piklist('field', array(
          'type' => 'select'
          ,'field' => 'user_relate_post'
          ,'label' => __('Relate Posts', 'piklist-demo')
      	,'attributes' => array(
            'multiple' => 'multiple' // Allow a select field to accept multiple selections
          )
          ,'choices' => piklist(
            get_posts(array(
              'post_type' => 'workshop'
              ,'numberposts' => -1
              ,'orderby' => 'title'
              ,'order' => 'ASC'
            ))
            ,array('ID', 'post_title')
          )
          ,'relate' => array(
            'scope' => 'post'
          )
        ));

      What I’d like to do now is display all users for a specific workshop. For example if a few users have ‘workshop 101’ selected on their pages -> show those users on the ‘workshop 101’ page. And vice versa.

      I’ve tried the basic functions but can’t seem to figure it out. Anyone have ideas? Is it possible?

    • #7299
      luxdelux
      Participant

      Ok I figured it out after checking the database entries and finding out how the meta_key is called.

      $temp = get_users(array( 'meta_key' => '__relate_post', 'meta_value' => ''.$postID.''));

    • #7304
      Steve
      Keymaster

      Great. Closing ticket

Viewing 2 reply threads
  • The topic ‘Get posts related from user and vice versa’ is closed to new replies.