how to get custom post type by user id/author

so, i’ve custom post type ‘pelajaran’. and I made the select option (location and subjects) search for custom post type.

I took the data (location + subjects) and the value from the user. this my code for select option

Read More
$query      = get_users('role=GURU&order=ASC&orderby=meta_value&meta_key=address');


<select name="location">
           <option>Location</option>
                <?php foreach ($query as $q) { 
                $address = get_the_author_meta('address', $q->ID); ?>
           <option value="<?php echo $q->ID; ?>"><?php echo $address; ?></option>

                <?php } ?>
 </select>

when the results came out, because the value of the id of the user. whether it can retrieve the data of custom post type from user id / author?

this my code for the result, on another page :

<?php
    global $current_user;
    get_currentuserinfo();

    $location = "";
    if (isset($_POST['location'])) {
        $location = $_POST['location'];
    }

    $args = array (
        'post_type' => 'pelajaran',
        'author'        =>  $current_user->ID,
        'posts_per_page'    => -1,
    );

    $pelajaran = get_posts($args);

    for($i=0;$i<sizeof($pelajaran);$i++) { ?>

     <?php if($location == $pelajaran[$i]->ID )
    echo ' '; //some my code html here

      ?>

 <?php } ?>

but, I still can not display the post data type of user id / author.
anyone can help me?
thanks in advance 🙂

Related posts

Leave a Reply