首页 > 解决方案 > 将短代码属性传递给 WordPress 远程发布 URL

问题描述

我正在尝试将简码属性值直接传递到我的 WordPress 远程发布请求的 URL 中。下面是我的代码示例。我在我的 wordpress 页面中使用以下简码

[示例数据开始=“1”计数=“10”]

但我无法让开始或计数数据在 URL 中工作。任何帮助,将不胜感激。

function display_example_data( $atts ) {

$value = shortcode_atts( array(
    'start' => 1,
    'count' => 10,
), $atts );

$url ="https://example.com/api/reviews?token=".$api_text_key."&start=".$value['start']."&count=".$value['count']."";

    $response = wp_remote_post( $url, array(
        'method' => 'GET',
        'timeout' => 45,
        'redirection' => 5,
        'httpversion' => '1.0',
        'blocking' => true,
        'headers' => array(),
        'cookies' => array()
        )
    );

<?php }

add_shortcode( 'example-data', 'display_example_data' );

标签: wordpressshortcode

解决方案


推荐阅读