Changes are made at your own risk and are not guaranteed to work. Always make backups of the database and files prior to implementing hacks. Make a special backup of the file and/or template you are modifying so that you can roll back quickly.
Hacks are dangerous and can cause your site to stop working. They make later updates to ExpressionEngine more difficult; you should track your hacks for post-update re-implementation.
Most hacks are unnecessary, please review the Development Documentation for information on expanding ExpressionEngine via Modules, Extensions, and Plugins.
Hacks are never officially supported.
Question:
How can I limit my entries in {exp:weblog:entries} to a particular custom field?
Easy Answer:
Mark Huot’s Custom Fields extension
Answer:
While you can orderby= custom field, it is not currently possibly to limit to a custom field. However, Solspace posted a hack for this in this thread
// ----------------------------------------------
// Limit by custom weblog field
// ----------------------------------------------
if ($custom_field = $TMPL->fetch_param('custom_field'))
{
$custom_field_array= explode('|',$custom_field);
if ($custom_field_name = $custom_field_array['1'] AND $custom_field_value = $custom_field_array['0'])
{
if (isset($this->cfields[$custom_field_value]))
{
$custom_field_id = $this->cfields[$custom_field_value];
}
$sql .= "AND exp_weblog_data.field_id_".$custom_field_id." = '".$custom_field_name."' ";
}
}
It goes in mod.weblog.php.
Inside the build_sql_query() function.
Sandwiched between the ‘Add status declaration’ block and the ‘Build sorting clause’ block.
You use it by passing string that looks like this:
custom_field_name|value
In the weblog tag parameter: custom_field
{exp:weblog:entries weblog="blog" custom_field="custom_field_name|value"}
Replace ‘custom_field_name’ with the name of the custom field your evaluating for. And replace ‘value’ with the value that the field needs to contain in order to fetch the relevant entries.
Hack at your own risk. No warranties, quarantees, or doggie fleas.
Category:Hacks Category:Templates Category:Entries
