M
M
Mikhail2021-02-12 05:37:29
Command line
Mikhail, 2021-02-12 05:37:29

Error on WP methods when running script file via console. Why?

<?php
echo 10;

$acc_active = get_terms( array(
    'taxonomy'  => 'acc', // название таксономии
    'hide_empty' => false,
    'meta_key' => 'vk_account_active', // ключ произвольного метаполя
    'meta_value' => '1', // значение произвольного метаполя
    // 'meta_query'    => $meta_query, // переменная с параметрами запроса

) );

echo '<p>Активных источников: <b>' . count($acc_active).'</b></p><hr>';

?>


echo works, but the WP method does not, although when run through the browser everything is fine.
What can be wrong?

Error text:
PHP Fatal error: Uncaught Error: Call to undefined function get_terms() ...
Stack trace:
#0 {main}
thrown in ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail, 2021-02-21
@Mishaermolaev

You just need to disable the theme file and include index.php

// Отключаем темы
define('WP_USE_THEMES', false);

// Заполним некоторые глобальные переменные
global $wpdb, $post, $wp_query, $paged, $page;

// получаем из index.php инициализацию ядра WP
require_once('/home/n/host/hostname/public_html/index.php');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question