LiveHelp
:: Our company :: Services :: Portfolio :: Information

Always something

fresh

Drupal taxonomy_select_nodes() limits results

In Drupal function taxonomy_select_nodes() limits results based on "Number of posts on main page" variable.

In API it says "Finds all nodes that match selected taxonomy conditions."

This sounds completly wrong if you consider this function could be called from custom modules to get entries for a custom block for example.

Either the admin:post settings option is mislabelled, either this function should be considered as usefull only for main page :/

if ($pager) {
  $result = pager_query($sql, variable_get('default_nodes_main', 10), 0, $sql_count, $args);
}
else {
  $result = db_query_range($sql, $args, 0, variable_get('feed_default_items', 10));
}

in modules/taxonomy/taxonomy.module, line 1078

http://api.drupal.org/api/function/taxonomy_select_nodes/6

Solution

I've find simple solution for this simple bug (or feature).

If you want set your custom result limit (whatewer you want), you should write this code:

global $conf;
$feed_items_tmp = isset($conf['feed_default_items']) ? $conf['feed_default_items'] : null;
$conf['feed_default_items'] = CUSTOM_INT_LIMIT; // It may be PHP_INT_MAX
$nodes_result = taxonomy_select_nodes( array($term->tid), 'or', 0, false, 'n.title ASC');
$conf['feed_default_items'] = $feed_items_tmp;

Note: In some cases you should use default_nodes_main key instead of feed_default_items if $pager input variable will be False. Just look in the code of taxonomy_select_nodes and you'll realize what it is about.

Good luck.

Share this

Comments:

In D6, I needed to set $pager='' (as well as this) to get > 10 results; // seems to be a danger of $pager being passed as a string

-Kenneth Thomas

Thank you ! It helped a lot !

This makes everything so cmoplteely painless.

Follow us

T F L