Datafeedr Support Forums

Datafeedr Support Forums (/index.php)
-   Questions (/forumdisplay.php?f=67)
-   -   Assign PHP Variable to ShortCode (/showthread.php?t=6540)

lesljr March 19th, 2012 04:30 PM

Assign PHP Variable to ShortCode
I figured out how to get related products into a widget. I just need to know how to assign a variable. Here is what I want to do. Thanks for your help

[DFR:Related Products?c=$dfr_category]

Store ID: 35889

$dfr_category = dfr_get_related_products();

[DFR:Related Products]

Eric March 19th, 2012 06:13 PM

I'm not sure what you are going for. Can you explain more?

lesljr March 19th, 2012 07:08 PM

ok here is what I have done. 1st I create a custom field for my post called dfr_category_number. This way i can assign a category number to a post.

Then I created a php function(code below) to get the product category from the post.


function dfr_get_related_products() {
$urlstr = $_SERVER['REQUEST_URI'];
$postidstr = url_to_postid( $urlstr );
return get_post_meta($postidstr, 'dfr_category_number', true);
Then I created a widget view to call dfr_get_related_products(code below)

$dfr_category = dfr_get_related_products();
[DFR:Related Products for Widget?c='$dfr_category']
Now inside the view I want to call a custom view using the dfr short code to get the related products. I have tested my php code, so I know that part works. i just need a way to dynamically call a view. The good thing about doing it this way is it will display related products in my sidebar if i have set it up, other wise it won't show any products.

Eric March 19th, 2012 08:00 PM

As long as your dfr_get_related_products() function is returning an ID, then this PHP code should do the trick:

PHP Code:

datafeedr_tag('Related Products for Widget?c='.$dfr_category);

lesljr March 19th, 2012 08:16 PM

that worked. thanks. your a rock star!

All times are GMT -5. The time now is 01:14 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.