Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:03:25+00:00 2026-06-09T16:03:25+00:00

I am using Drupal 6 and have multiple flags on my nodes each with

  • 0

I am using Drupal 6 and have multiple flags on my nodes each with a value such as: interesting, boring, intelligent, funny, abusive, etc. Views is currently able to sort results by the flag count for each individual flag but I need to sort my nodes by the total combined flag count of all the flags on each note. The ‘rate’ module comes fairly close to doing this but I need to use the flag module so that I can use the flag solr module to allow searching by flag. I just really don’t know where to start… any suggestions as to an approach I could take?

Here’s the current views query;

SELECT node.nid AS nid, 
flag_counts_node.count AS flag_counts_node_count,    
flag_counts_node_1.count AS flag_counts_node_1_count, 
flag_counts_node_2.count AS flag_counts_node_2_count, 
flag_counts_node_3.count AS flag_counts_node_3_count, 
flag_counts_node_4.count AS flag_counts_node_4_count FROM node node  
LEFT JOIN flag_counts flag_counts_node ON node.nid = flag_counts_node.content_id AND flag_counts_node.fid = 7 
LEFT JOIN flag_counts flag_counts_node_1 ON node.nid = flag_counts_node_1.content_id AND flag_counts_node_1.fid = 6 
LEFT JOIN flag_counts flag_counts_node_2 ON node.nid = flag_counts_node_2.content_id AND flag_counts_node_2.fid = 4 
LEFT JOIN flag_counts flag_counts_node_3 ON node.nid = flag_counts_node_3.content_id AND flag_counts_node_3.fid = 5 
LEFT JOIN flag_counts flag_counts_node_4 ON node.nid = flag_counts_node_4.content_id AND flag_counts_node_4.fid = 3 
WHERE (node.type in ('rpodcast', 'upodcast')) AND (node.status = 1) ORDER BY flag_counts_node_count ASC, flag_counts_node_1_count ASC, flag_counts_node_2_count ASC, flag_counts_node_3_count ASC, flag_counts_node_4_count ASC

Here the module code so far ;

<?php
function flagcountview_views_pre_execute(&$view){
if ($view->name == 'audio') {
$sql = $view->build_info['query']; 
$flag_count = "flag_counts_node.count + flag_counts_node_1.count +  flag_counts_node_2.count + flag_counts_node_3.count"; 
$sql .= "ORDER BY $flag_count DESC"; 
$view->build_info['query'] = $sql;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:03:26+00:00Added an answer on June 9, 2026 at 4:03 pm

    Hi seems like you cant add fields, so we can try alternate approach

    function flagcountview_views_pre_execute(&$view){
      if ($view->name == 'audio') {
        $sql = $view->build_info['query']; 
        $search = "ORDER BY flag_counts_node_count ASC, flag_counts_node_1_count ASC, flag_counts_node_2_count ASC, flag_counts_node_3_count ASC, flag_counts_node_4_count ASC";
        $replace = "ORDER BY flag_counts_node.count + flag_counts_node_1.count +  flag_counts_node_2.count + flag_counts_node_3.count ASC"; 
        $sql = str_replace($search, $replace, $sql);; 
        $view->build_info['query'] = $sql;
      }
    }
    

    Make sure you added all flag count in view -> sort criteria 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Drupal and I have a list of items (View with many nodes)
I'm using Drupal 7 and I have to make a union on multiple tables.
I am using Drupal and have sifr set on list items, and also a,
I'm using Drupal 6 and have created 2 equal columns in layout.css In the
I have this website iloveforwards.com created using drupal. I would like to have a
I'm using Drupal and I notice that if I have my CSS files aggregated
I'm using Drupal 6. I have a custom view that needs to be filtered
I am using drupal 7 with apachesolr module. I have an external file field
I am using Drupal 6.13, Views 6.x-2.6, Voting API 6.x-2.3, Fivestar 6.x-1.18. I have
I have Drupal 6 website which is using FCK Editor as HTML editor. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.