2

I have an existing DB with entries that have been assigned to authors via the native Members module as well as Solspace's User module.

Unfortunately, the User module doesn't take into account entries that have been assigned to a member via the native module when using the exp:user:entries loop — and the opposite is true as well, of course. This means that, on a user profile page, there's no way to get a list of entries using both assignments.

How can I get a list of results that includes both assignments?

Updated to say: the issue is entries with multiple authors. Some entries have User data (entries with multiple authors) and some don't. I may end up manually having to enter User data for all entries, but there are a few hundred.

(I'm guessing we might have to head into Query territory, which is just beyond my capabilities at the moment.)

  • 2
    Are you sure about that? AFAIK, unless you're assigning multiple authors to an entry (via the User Authors feature), both modules look at the exact same data (namely, the author_id column in the exp_channel_titles table). – Derek Hogue Jan 11 '13 at 20:25
  • Sorry, the issue is exactly that — a number of entries have multiple authors. – Tim Jan 12 '13 at 3:04
2

You are correct - when using the User Authors feature, all authorship data is stored in the exp_user_authors table.

This script should fill in the gaps in your User Authors table for you. Backup your database, create a new template, enable PHP on it, put this in it (replace $channel_id at the top with your actual channel_id), then load the template i your browser:

<?php

$this->EE =& get_instance();

$channel_id = 1;

$entries = $this->EE->db->query("
    SELECT entry_id, author_id, entry_date
    FROM exp_channel_titles 
    WHERE channel_id = $channel_id
");
if($entries->num_rows() > 0)
{
    foreach($entries->result_array() as $entry)
    {
        extract($entry);
        // Make sure an author entry doesn't already exist
        $existing = $this->EE->db->query("
            SELECT entry_id 
            FROM exp_user_authors 
            WHERE entry_id = $entry_id
            AND author_id = $author_id
        ");
        if($existing->num_rows() == 0)
        {
            // No entry exists, so insert it
            $data = array(
                'author_id' => $author_id,
                'entry_date' => $entry_date,
                'entry_id' => $entry_id,
                'principal' => 'y'
            );
            $this->EE->db->query(
                $this->EE->db->insert_string('exp_user_authors', $data)
            );
        }
    }
}

?>
| improve this answer | |
  • Seems to have worked like a charm, thanks a lot. – Tim Jan 15 '13 at 17:37
  • Glad to hear it! – Derek Hogue Jan 15 '13 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.