dqxsuig64994 2016-05-03 08:43 采纳率: 0%
浏览 32
已采纳

记住下一页的slug

First off, sorry for the long read. But I hope that this better explains what I'm trying to do...

I'm probably trying something that cannot be done. But I'll ask the question anyway.

I got a custom post type (beachevents) in this custom post type I have my beachevents-posts. There all in the loop loop-beachevents, don't know if that matters anything, but ok.

I also have some locations like Noord Holland, Zuid Holland and Flevoland. Locations is a custom taxonomy (locations_noord_holland, locations_zuid_holand etc.)

The taxonomy locations_noord_holland is filled with cities in Noord Holland, like Amsterdam for this question.

When you go to Home -> Locations -> Noord Holland -> Amsterdam URL is: home.nl/locaties/noord-holland/amsterdam (where amsterdam is the Slug).

In this screen have some text about the beachevents in Amsterdam. Also it Gets the slug Amsterdam with the following code:

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?>

With returns "Beachevents in Amterdam" as the title.

Ok now for the code part. When you click on a beachevent in Amsterdam it will link you to home.nl/activiteiten/your-beachevent/ (activiteiten is a custom post type rewrite from the custom post type beachevents)

On that page there is a hidden contact form7 which is activated using fancybox. Using this code:

<a class="my-subject fancybox-offerte" href="#offerte" dataTitle="<?php echo $subject; ?>"><div class="btn btn-04">Offerte aanvragen</div></a>

The dataTitle is there so the contact form7 know what beachevents is selected and automatically sets this value in the contact form as "beachevent" this all works in combination with the "Dynamic Content plugin in for Contactform 7".

So, that explains the lot. Now what I would like is to have Wordpress remember from what slug (in this case Amsterdam) the user came from and add this city to the contact form using the dynamic content plugin.

What I know is that I have to tell Wordpress to remember the slug Amsterdam (or any other city from Noord Holland, Zuid Holland or Flevoland). And store this value in any form so the contact form knows where to put this information.

In the contact form I can add the following:

<li class="low-li">[dynamictext text-uitje id:txt-uitje class:dy-text "CF7_ADD_CITY"]</li>

And then I add this code to my function file:

function cf7_add_city() {
     global $post;
         $city = get_field('stad');
            return $city;
}

add_shortcode('CF7_ADD_CITY', 'cf7_add_city');

But this only works if i set the city in some advanced custom field and get it's value. But this does not get the (dynamic) slug that I would like to have Wordpress remember from the previous page.

Can anyone help me with this? Is this at all possible?

  • 写回答

3条回答 默认 最新

  • douzhaobo6488 2016-05-03 08:48
    关注

    You could set it in $_SESSION every time you load that page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?