I’m creating a custom module and content type. And show this items on my page. My module is:
function theme_news(){
global $language;
$output = '';
drupal_set_title('News');
$m_query = db_select("node","n")->extend("PagerDefault")->limit(10);
$m_query->fields("n",array('nid','title','language'));
$m_query->condition('status','1',"=");
$m_query->condition('n.type','news','=');
//$m_query->condition('n.language',$language->language,'=');
$m_query->orderBy('n.sticky','desc');
if(arg(1) == 'latest_news'){
$m_query->join('field_data_field_etype','fe','n.nid=fe.entity_id');
$m_query->condition('fe.field_etype_value','ap','=');
if(arg(2) != ''){
$m_query->join('field_data_field_myear','fy','n.nid=fy.entity_id');
$m_query->condition('fy.field_myear_value',arg(2),'=');
}
}
if(arg(1) == 'feature_news'){
$m_query->join('field_data_field_etype','fe','n.nid=fe.entity_id');
$m_query->condition('fe.field_etype_value','sp','=');
if(arg(2) != ''){
$m_query->join('field_data_field_myear','fy','n.nid=fy.entity_id');
$m_query->condition('fy.field_myear_value',arg(2),'=');
}
}
This function creates 2 sub menus and shows the contents in these submenus. Working my code but i don’t know, why I don’t see field_myear value.
How can i fix that?
I’d suggest that you solve your task by combining Drupal views and filters, instead of crafting custom SQL queries in your custom module, right away. In most cases this is sufficient, and leads to less headache later.
conditionclauses should be view filters.joins should be view relationshipsand your custom fields should be CCK fields indeed.