I need to list my wordpress today’s articles in a short div.
So far, I (think I) have made a proper code to list today’s articles but for some reason it says this:
Fatal error: Call to undefined function add_action() in
/home/u783756934/public_html/wp-content/themes/wordplus/functions.php
on line 30
My code is this:
<?php
include "functions.php";
$query = new WP_Query( 'year=' . the_time('Y') . '&monthnum=' . the_time('m') . '&day=' . the_time('d') );
$posts = $query->get_posts();
foreach ( $posts as $post )
{
echo($post->post_title);
}
?>
My functions.php file is original and unedited.
TLDR:
I need to list articles that have been posted today so I can embed the output on another website.
Probably you are trying to run it outside of your theme’s core files – it is called without any of the processing WordPress is supposed to do before
add_action()
function. This must be in your theme’s functions.php file or within a plugin.You must add the line
require(dirname(__FILE__) . '/wp-load.php');
before the other functions. This should solve your problem.Also Remember
dirname(__FILE__)
is should point to root WordPress directory, like http://www.yourwebsite.com/wordpress/The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress site.
You did not require to include it in your theme file. So, remove that first statement (include functions.php) from the code and your code will work fine.
Funcstion.php behaviour.