Support

Account

Home Forums Front-end Issues Attach Users to Custom Post Type? Reply To: Attach Users to Custom Post Type?

  • Hi @rickygreen

    Multiple users field is saved in a serialized data like this: a:3:{i:0;s:3:"810";i:1;s:3:"135";i:2;s:3:"814";}.

    I believe you can query the investment custom posts using this arguments code:

    $userID = $current_user->ID;
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'	=> 'investment_cpt',
    	'meta_query'	=> array(
    		array(
    			'key'		=> 'investors_attach',
    			'value'		=> serialize(strval($userID)),
    			'compare'	=> 'LIKE'
    		),
    	)
    );

    Where ‘investment_cpt’ is the custom post type of your investment.

    Please take a look at this page again to learn more about it: http://www.advancedcustomfields.com/resources/query-posts-custom-fields/.

    I hope this helps.