• I am asking for a query I would like to use inside my blog, that searches MySql.

    The query has to look inside the wp_usermeta, and check whether the new field I made with name “support” is equal to 1.

    After that it will display all the users that have the field support equal to meta_key 1.

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Nikolas

    (@kordellas)

    maybe this will help someone?

    <?php
    
     $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'tag'
        AND wpostmeta.meta_value = 'email'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wposts.post_date < NOW()
        ORDER BY wposts.post_date DESC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>

    or

    <?php
    //get all users, iterate through users, query for one post for the user, if there is a post then display posts title, author, content info
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $args = array(
        'author' => $bloguser->user_id,
    	  'showposts' => 1,
    	  'caller_get_posts' => 1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          // $user = get_userdata($bloguser->user_id);
          // echo 'This is one post for author with User ID: ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?> </small><?php
            the_content();
          endwhile;
        }
      }
    }
    ?>

    Your first code suggestion is the better of the two imo. Nice one posting back your solution(s).. ??

    Thread Starter Nikolas

    (@kordellas)

    Hello t31os_

    thank you for your reply.

    Well this code ( the first one ) searches posts am I right?

    I know about the AND, OR stuff, it says to display wposts by it’s day where some tags are available.

    But how to turn it and look the authors instead of posts?

    Thread Starter Nikolas

    (@kordellas)

    .. and after this, it will create a new field that contains all the id’s that meet the requirements

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sql query that shows all users with meta_key equals to 1’ is closed to new replies.