Get Author Id inside of td_module_2.php

Posted in: Newspaper
Post count: 12

Hi Team,

Simple… I need to get the author id inside of td_module_2.php loop

<div class=”td-module-meta-info”>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php echo $this->get_comments();?>

//example
<?php echo $this->get_author_id();?> —/ or something like that
</div>

this is because a need to pass to other function this ID in this place, thanks for all your help

  • This topic was modified 9 years by virgilio.
Post count: 22421

Hello,

You can use a few WordPress functions that can grab the author id like for example: https://developer.wordpress.org/reference/functions/get_the_author_meta/

Thank you!

Post count: 12

Hi Bodgan,

Thanks for your help, but get_the_author_meta() in that case don’t show me the id of the author of the post in that loop, here the complete code:

<?php

/**
* this module is for Especialistas
* Class td_module_200
*/

class td_module_200 extends td_module {

function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}

function render() {
ob_start();
?>

<div class=”<?php echo $this->get_module_classes();?>”>
<?php
// i need print here the id of author
$id_foto = get_the_author_meta(‘ID’);
userphoto($id_foto);
?>
<div class=”item-details”>
<?php echo $this->get_title();?>

<div class=”td-module-meta-info”>
<?php if (td_util::get_option(‘tds_category_module_16’) == ‘yes’) { echo $this->get_category(); }?>
<?php echo $this->get_author();?>
<?php echo $this->get_date();?>
<?php echo $this->get_comments();?>
</div>
</div>

</div>

<?php return ob_get_clean();
}

}

Post count: 12

Ready!

i can get the solution, just put a new function inside of td_module.php

function get_author_id() {
$buffy = get_the_author_meta(‘id’, $this->post->post_author);
return $buffy;
}

and then call this at td_module_2.php

<div class=”td-module-meta-info”>
<?php if (td_util::get_option(‘tds_category_module_16’) == ‘yes’) { echo $this->get_category(); }?>
<?php echo $this->get_author();?>
<?php echo $this->get_author_id();?> //<—— READY
<?php echo $this->get_date();?>
<?php echo $this->get_comments();?>
</div>

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.