My requirement is to sort the nodes with a "condition" based on whether a field called myfield has value in it or not and then by date created. That means, show nodes first if a field has value and then by datecreated.

its something like this sql query

select field1,
       if(isnull(myfield,1),1,0) hasvalue

from table
order by hasvalue asc, datecreated desc

For doing this I learnt that I need to create a module called tdyards and implemented tdyards_views_query_alter in tdyards.views.inc with this code in it and enabled the module.


function tdyards_views_query_alter(&$view, &$query) {
    print "<h1>I am in tdyards alter query</h1>";

I was expecting this pileup my screen with the dump but it seems like it is never called this function. Am I missing anything else here? If my guess is correct it must call this for each and every view because my implementation doesn not have any condition

  • Hello. Could you edit your question's title? Body seems pretty OK, but title looks like you are looking for tutorials etc and that's explicitly off-topic, so it creates impression you don't want. – Mołot Feb 27 '14 at 13:24
  • have you cleared your caches since creating this function? if not, drupal won't know to look for it. – Jimajamma Feb 27 '14 at 14:39
  • yes sir. its weird that Alexei Rayu suggestion in my early post did the trick. I had to add it in .module for it to work. Looking for someone to help me understand this why and how – Dudepal Feb 27 '14 at 15:19

Your Answer

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

Browse other questions tagged or ask your own question.