最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Upload advanced custom field text link array with csv

programmeradmin3浏览0评论

On my webshop I have to see a button with a link to ad pdf file. For every product that button need to have a different link and a different button title name.

I built the webshop with woocommerce where I used Advanced Custom fields to show the buttons with a pdf link. In ACF I used a link array. On the product page I can change the title text of the link manually.

But. There are more than 1000 products. So it's not possible to do this manually. I imported a csv with the right header names. And importing the columns with links to the buttons works properly.

In the php code I used this standard acf code:

<?php 
$link = get_field('link');
if( $link ): 
    $link_url = $link['url'];
    $link_title = $link['title'];
    $link_target = $link['target'] ? $link['target'] : '_self';
    ?>
    <a class="button" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
<?php endif; ?>

So, what meta data I have to give in my csv file to fill in the link title? --> The title on the button.

On my webshop I have to see a button with a link to ad pdf file. For every product that button need to have a different link and a different button title name.

I built the webshop with woocommerce where I used Advanced Custom fields to show the buttons with a pdf link. In ACF I used a link array. On the product page I can change the title text of the link manually.

But. There are more than 1000 products. So it's not possible to do this manually. I imported a csv with the right header names. And importing the columns with links to the buttons works properly.

In the php code I used this standard acf code:

<?php 
$link = get_field('link');
if( $link ): 
    $link_url = $link['url'];
    $link_title = $link['title'];
    $link_target = $link['target'] ? $link['target'] : '_self';
    ?>
    <a class="button" href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
<?php endif; ?>

So, what meta data I have to give in my csv file to fill in the link title? --> The title on the button.

Share Improve this question edited Oct 30, 2019 at 7:15 Jacob Peattie 44.2k10 gold badges50 silver badges64 bronze badges asked Oct 28, 2019 at 21:53 NielsD4NielsD4 1
Add a comment  | 

1 Answer 1

Reset to default 0

If you make a var_dump() on $link:

var_dump('<pre>', $link);

then you will see all array keys and you can choose the one you need.

发布评论

评论列表(0)

  1. 暂无评论