Vimeo API для WordPress сообщений - PullRequest
2 голосов
/ 14 февраля 2020

Я перечислил видео vimeo с канала, используя vimeo api, используя php Теперь я хочу загрузить все видео в виде сообщения в WordPress настраиваемый тип записи, как это сделать? каждый раз, когда я публикую новое видео, оно должно добавлять видео в виде поста к пользовательскому типу

1 Ответ

0 голосов
/ 14 февраля 2020

Чтобы создать сообщение в WordPress, вы можете использовать следующий код:

Step1:

Найдите вариант веб-хитов Vimeo, который даст вам знать, когда будет опубликовано новое видео Vimeo. Таким образом вы можете получить подробную информацию о видео, а затем использовать эту информацию для создания поста в WordPress.

Ссылка Vimeo API: https://developer.vimeo.com/help

Интеграционная связь Zapier Vimeo: https://zapier.com/apps/vimeo/integrations/webhook

Шаг 2 :

/**
 * A function used to programmatically create a post in WordPress. The slug, author ID, and title
 * are defined within the context of the function.
 *
 * @returns -1 if the post was never created, -2 if a post with the same title exists, or the ID
 *          of the post if successful.
 */
function programmatically_create_post() {

    // Initialize the page ID to -1. This indicates no action has been taken.
    $post_id = -1;

    // Setup the author, slug, and title for the post
    $author_id = 1;
    $slug = 'example-post';
    $title = 'My Example Post';

    // If the page doesn't already exist, then create it
    if( null == get_page_by_title( $title ) ) {

        // Set the post ID so that we know the post was created successfully
        $post_id = wp_insert_post(
            array(
                'comment_status'    =>  'closed',
                'ping_status'       =>  'closed',
                'post_author'       =>  $author_id,
                'post_name'     =>  $slug,
                'post_title'        =>  $title,
                'post_status'       =>  'publish',
                'post_type'     =>  'post'
            )
        );

    // Otherwise, we'll stop
    } else {

            // Arbitrarily use -2 to indicate that the page with the title already exists
            $post_id = -2;

    } // end if

} // end programmatically_create_post
add_filter( 'after_setup_theme', 'programmatically_create_post' );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...