• Hey guys, a new project I have the following code to fill an option, which is running normally while listing all data.

    <select name="agent_id" id="agent-selectbox">
    	<?php
    	$agents_args = array( 'post_type' => 'agent', 'posts_per_page' => -1 );
    	$agents = get_posts( $agents_args );
    	foreach ( $agents as $agent ) :
    		?><option value="<?php echo $agent->ID; ?>" <?php if( isset($post_meta_data['themes_agents']) && ($post_meta_data['themes_agents'][0] == $agent->ID ) ){ echo "selected"; } ?>><?php echo $agent->post_title; ?></option><?php
    	endforeach;
    	?>
    </select>

    But, I would like to add a new parameter to query, tried adding via code, but does not work.

    $agents_args = array( 'post_type' => 'agent', 'posts_per_page' => -1, 'id_usuario' => $user_id );

    Recalling that the problem is not in my variable therefore contains the same data. Just do not know for PHP OO way.
    ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    What is ‘id_usuario’? A custom field or the WP user ID? All arguments to the left of => have to be a label recognized by the query parser. If you want to use a label you created on the left you are doing it wrong.

    If for a custom field, do this:

    $agents_args = array(
      'post_type' => 'agent',
      'posts_per_page' => -1,
      'meta_key' => 'id_usuario',
      'meta_value' => $user_id,
    );

    If not a custom field, where is the ID stored? Post author? The ID must somehow be related to a post, please explain that relationship.

    If you’re trying to pull out the posts from a particular author, you should be using the “author” attribute for the get_posts function.

    $agents_args = array( 'post_type' => 'agent', 'posts_per_page' => -1, 'author' => $user_id );

    If the ‘id_usuario’ is a custom parameter then you might create a function in your plugin that processes the data and then calls ‘get_posts’.

    Thread Starter leonidasw

    (@snniffer)

    Well, sorry for the delay in responding.

    The user_id field was created by me for an internal control. And I would add the user_id consultation.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add argument in consultation’ is closed to new replies.