Forum Replies Created

Viewing 15 replies - 46 through 60 (of 83 total)
  • This is now happening for one of our sites as well. Looking for info.

    Thread Starter pixelnate

    (@pixelnate)

    Shameless bump.

    Thread Starter pixelnate

    (@pixelnate)

    That’s a good idea. It would be a lot easier to reformat the content. Fortunately I don’t need to paginate the results and there are only about 60 names to reverse. I think that’s the way I’ll go. Thanks. I’ll mark this as resolved and open a new thread later if I run into problems. Thanks, again.

    Thread Starter pixelnate

    (@pixelnate)

    That would be the quickest way to solve the problem, but it seems so amateur to tell my client that they would need to enter the names of the golfers twice. I’ll bring that up to the sales rep, but it still feels a bit dirty.

    Thread Starter pixelnate

    (@pixelnate)

    Sam, good to have you on the other end of a question again. Nice looking solution, too, but I’ll have to wait until Monday to test it when I get in the office. Sometimes it takes a few days to get an answer in here and I wanted to cast the net and see what came up before heading into the week.

    You are right about the strange/non-standard names. I have a couple of juniors and seniors in there, and maybe one of two multi-word last names. I could turn that first filter into an if-then-else statement couldn’t I?

    Been following Emily’s blog, too. It’s good to hear that she’s making progress. I cannot imagine what y’all must be going through.

    Thread Starter pixelnate

    (@pixelnate)

    Once again, you save my life on this project. Thanks.

    It just goes to show me that I need to bone up on PHP. I went looking for something that did what usort does and couldn’t find it. Help me, though, understand how the strnatcmp command works in that function. Is it comparing every last name against every other last name? The whole $a $b this what is confusing me. Strnatcmp only accepts two parameters, so you can’t just do a usort on the $users array, but I wouldn’t have thought you could use it in that way.

    Thread Starter pixelnate

    (@pixelnate)

    OK, I have just one more question. How can I order the results of the query by the user ‘last_name’ values?

    $sql = "SELECT * FROM $wpdb->usermeta
    		WHERE user_id IN (SELECT um1.user_id FROM $wpdb->usermeta um1 WHERE um1.meta_key = 'director')
    		AND meta_key IN (
    			'first_name',
    			'last_name',
    			'director',
    			'nickname',
    			'sub_director',
    			'job_title',
    			'office_phone_area',
    			'office_phone_prefix',
    			'office_phone_suffix',
    			'mobile_phone_area',
    			'mobile_phone_prefix',
    			'mobile_phone_suffix',
    			'fax_area',
    			'fax_prefix',
    			'fax_suffix'
    		)
    		ORDER BY $wpdb->usermeta . 'last_name' ASC
    		";

    This isn’t working.

    Thread Starter pixelnate

    (@pixelnate)

    This works perfectly! Thank you very much.

    Do you have a paypal account? I’d like to buy you a beer.

    Thread Starter pixelnate

    (@pixelnate)

    It does indeed work. Brilliantly. Thank you.

    But I have one more request. Could you please show me how to do a join on the query to include fields from the user table so that I can make use of the a user’s email when showing the rest of the user’s info?

    This is what the whole of the code looks like now:

    $title = get_the_title();
    
    $sql = "SELECT * FROM $wpdb->usermeta
        WHERE user_id IN (SELECT um1.user_id FROM $wpdb->usermeta um1 WHERE um1.meta_key = 'director')
        AND meta_key IN (
            'first_name',
            'last_name',
            'director',
            'nickname',
            'sub_director',
            'job_title',
            'office_phone_area',
            'office_phone_prefix',
            'office_phone_suffix',
            'mobile_phone_area',
            'mobile_phone_prefix',
            'mobile_phone_suffix',
            'fax_area',
            'fax_prefix',
            'fax_suffix'
        )";
        $rows = $wpdb->get_results($sql);
    
        $users = array();
    
        foreach ($rows as $row) {
            $users[$row->user_id][$row->meta_key] = $row->meta_value;
            $users[$row->user_id]['user_id'] = $row->user_id;
        }
    
    foreach ($users as $user) {
        $director_id = $user['user_id'];
        $firstname = $user['first_name'];
        $lastname = $user['last_name'];
        $director = $user['director'];
        $sub_director = $user['sub_director'];
        $job_title = $user['job_title'];
        $email = $user['user_email'];
        $phone1 = $user['office_phone_area'];
        $phone2 = $user['office_phone_prefix'];
        $phone3 = $user['office_phone_suffix'];
        $mphone1 = $user['mobile_phone_area'];
        $mphone2 = $user['mobile_phone_prefix'];
        $mphone3 = $user['mobile_phone_suffix'];
        $fax1 = $user['fax_area'];
        $fax2 = $user['fax_prefix'];
        $fax3 = $user['fax_suffix'];
    
        if (strpos($director,$title) !== false) {
            echo userphoto_thumbnail($director_id);
            echo "<p><span>$firstname $lastname</span>";
            if ($job_title !== '') { echo "<br /><span class=\"position\">$job_title</span>"; }
            if ($phone1 !== '' && $phone2 !== '' && $phone3 !== '') { echo "<br /><span class=\"phone\">($phone1) $phone2 - $phone3</span>"; }
            if ($mphone1 !== '' && $mphone2 !== '' && $mphone3 !== '') { echo "<br /><span class=\"phone\">($mphone1) $mphone2 - $mphone3</span>"; }
            if ($fax1 !== '' && $fax2 !== '' && $fax3 !== '') { echo "<br /><span class=\"phone\">($fax1) $fax2 - $fax3</span>"; }
    
        }
    }

    Thread Starter pixelnate

    (@pixelnate)

    The user arrays are nested in the user array like they were in the rows array. So I think that would make the users array an object. Not sure how to make the user meta info usable in that case.

    Thread Starter pixelnate

    (@pixelnate)

    I am apparently a just a disaster with custom PHP. This is what I have so far:

    $sql = "SELECT * FROM $wpdb->usermeta
        WHERE user_id IN (SELECT um1.user_id FROM $wpdb->usermeta um1 WHERE um1.meta_key = 'director')
        AND meta_key IN ('first_name','last_name','director','nickname')";
        $rows = $wpdb->get_results($sql);
    
    $users = array();
    
    foreach ($rows as $row) {
        $users[$row->user_id][$row->meta_key] = $row->meta_value;
        $users[$row->user_id]['user_id'] = $row->user_id;
    }
    
    foreach ($users as $user) {
        if (strpos($user->meta_value,$title) !== false) {
            echo "<p>$user->firstname $user->lastname</p>";
        }
    }

    And the last foreach loop responds by producing absolutely nothing, but it should. Any thoughts?

    Thread Starter pixelnate

    (@pixelnate)

    If I do a print_r on the $rows array I can see that, but if I do a print_r on the $users array from your example all I get are the meta field data.

    Could you perhaps give a little explanation of what this is doing?

    foreach ($rows as $row) {
    		   $users[$row->user_id][$row->meta_key] = $row->meta_value;
    		}

    I am having trouble grokking it. Perhaps I shoud just pull my values from the rows array?

    Thread Starter pixelnate

    (@pixelnate)

    One more question on this. While the latest query pulls all the meta data out of the usermeta table, I also need to get the user_id out of the table. How can I retrieve the id from the the usermeta table with the rest of the data?

    Thread Starter pixelnate

    (@pixelnate)

    I’ll have to try that. Thanks again.

    Thread Starter pixelnate

    (@pixelnate)

    That works great. Using strpos instead of breaking the director values up and putting them in an array was a stroke of genius.

    One question, though. Because the query is made up of all the joins, it only includes what is in the joins. Will this create a performance problem if I add another 5 or 6 keys to the join?

Viewing 15 replies - 46 through 60 (of 83 total)