I have a simple plugin that runs a query and returns a single value.
{exp:company_id id='{segment_3}'}
This outputs a number such as 5081
If I do this:
{preload_replace:cid="{exp:company_id id='{segment_3}'}"}
{cid}
It works as well.
If I drop either {cid} or {exp:company_id id='{segment_3}'} into a query
{exp:query sql="select field_id_10 as facebook, field_id_11 as twitter, field_id_13 as linkedin, field_id_15 as youtube from exp_channel_data where field_id_4 = '{exp:company_id id='{segment_3}'}'" parse="inward"}
Either using parse inward or not ... or using the preload or plugin the value in debugging shows : M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr
I am a bit stumped at this point. Any pointers would be much appreciated.
Updated:
Taking Advice Below I got this to work both ways: {exp:company_id id="123456"}{/exp:company_id} and {exp:company_id}{segment_3}{/exp:company_id}
var $return_data;
function company_id()
{
$this->EE =& get_instance();
$tagdata = $this->EE->TMPL->tagdata;
$id = ($this->EE->TMPL->fetch_param('id')) ? $this->EE->TMPL->fetch_param('id') : $this->EE->TMPL->tagdata ;
$id = $this->_get_id($id);
$this->return_data = $id;
}
function _get_id($id)
{
// Query
$this->results = $this->EE->db->query('SELECT company_id FROM '.$this->EE->db->dbprefix('jobs').' WHERE job_id = '.$id.' LIMIT 1');
if($this->results->num_rows() == 0) :
if($this->errors == 'false') :
return null;
else :
return null;
endif;
else :
return $this->results->row('company_id');
endif;
}