I have a function as shown below defined inside chapters.php file. In the function below, I am trying to retrieve all wordpress post having type sdft-episodes.
=> chapters.php:
namespace SDFT\Chapters;
function get_down_latest_videos( $post_id ) {
$query = new WP_Query(array(
'post_type' => 'sdft-episodes',
'post_status' => 'publish',
));
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
}
}
I want to call this function in a different file. The file name where I want to call the above function is down-latest-videos.php.
=> down-latest-videos.php:
Here is the complete path and code inside down-latest-videos.php:
$latest_four_vods = \SDFT\Chapters\get_down_latest_videos( $post_id );
print_r($latest_four_vods); // Line A
The above code is inside the file down-latest-videos.php. Line A above doesn't print anything.
Problem Statement :
I am wondering what changes I should make in the function above so that when it is called anywhere it should show all the wordpress post having type sdft-episodes
.
Line A should print should print all wordpress post having type sdft-episodes
.
I have a function as shown below defined inside chapters.php file. In the function below, I am trying to retrieve all wordpress post having type sdft-episodes.
=> chapters.php:
namespace SDFT\Chapters;
function get_down_latest_videos( $post_id ) {
$query = new WP_Query(array(
'post_type' => 'sdft-episodes',
'post_status' => 'publish',
));
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
}
}
I want to call this function in a different file. The file name where I want to call the above function is down-latest-videos.php.
=> down-latest-videos.php:
Here is the complete path and code inside down-latest-videos.php:
$latest_four_vods = \SDFT\Chapters\get_down_latest_videos( $post_id );
print_r($latest_four_vods); // Line A
The above code is inside the file down-latest-videos.php. Line A above doesn't print anything.
Problem Statement :
I am wondering what changes I should make in the function above so that when it is called anywhere it should show all the wordpress post having type sdft-episodes
.
Line A should print should print all wordpress post having type sdft-episodes
.
1 Answer
Reset to default 1Make sure you're namespacing the class that is declaring the function, within chapters.php
- namespace absf/Chapters
Within down-latest-videos.php
:
use function absf\Chapters\get_down_latest_videos; // This pulls in the function from chapters.php
$latest_four_vids = get_down_latest_videos( $post_id );
Your function get_down_latest_videos
is expecting one argument to be passed - $post_id
.
You're passing it two - $curated_posts
and $program_ids
.
Since you're filtering the posts within the WP_Query
, you don't need to pass in a $post_id
or any arguments, unless you're using those in the function itself to add to the filter. Currently you're not using $post_id
anywhere within the function.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745037055a4607585.html
评论列表(0条)