Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having issues with a custom url. I have a page with a gallery type plugin/shortcode. Now each gallery item displayed on the page, has a readmore link, linking to that gallery item post.

Now I created my own custom url variable that can be set on the gallery item post:

enter image description here

This was added like this on the recipe_options.php page, where you can set the various options on each gallery item post.

$recipe_url = '';

This was added like this to the recipe_options.php page:

function add_recipe_option_element(){
        $recipe_price = '';
        $recipe_social = '';
        $sidebars = '';
        $right_sidebar_recipe = '';
        $left_sidebar_recipe = '';
        $recipe_detail_xml = '';
        $select_chef = '';
        $recipe_url = '';


    foreach($_REQUEST as $keys=>$values){
        $$keys = $values;
    }
    global $post;

    $recipe_detail_xml = get_post_meta($post->ID, 'recipe_detail_xml', true);
    $ingredients_settings = get_post_meta($post->ID, 'ingredients_settings', true);
    $nutrition_settings = get_post_meta($post->ID, 'nutrition_settings', true);

    if($recipe_detail_xml <> ''){

        $cp_recipe_xml = new DOMDocument ();
        $cp_recipe_xml->loadXML ( $recipe_detail_xml );
        $recipe_price = find_xml_value($cp_recipe_xml->documentElement,'recipe_price');
        $recipe_url = find_xml_value($cp_recipe_xml->documentElement,'recipe_url');
        $recipe_social = find_xml_value($cp_recipe_xml->documentElement,'recipe_social');
        $sidebars = find_xml_value($cp_recipe_xml->documentElement,'sidebars');
        $left_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'left_sidebar_recipe');
        $right_sidebar_recipe = find_xml_value($cp_recipe_xml->documentElement,'right_sidebar_recipe');
    }

//AND further down on the recipe_options.php page

<ul class="recipe_class">
    <li class="panel-title">
        <label for="recipe_url" > <?php _e('RECIPE URL', 'crunchpress'); ?> </label>
    </li>               
    <li class="panel-input">
        <input type="text" name="recipe_url" id="recipe_url" value="<?php if($recipe_url <> ''){echo $recipe_url;};?>" />
    </li>
    <li class="description"><p>Please enter your url</p></li>
</ul>   
<div class="clear"></div>

The LINK

This is the part, on the same recipe_options.php page, where you set the href property for the 'read more' link:

<article class="menu-det">
    <p><?php echo strip_tags(mb_substr(get_the_content(),0,$num_excerpt));?> <a class="c-link" href="<?php echo $recipe_url ;?>"><?php _e('Read M...', 'crunchpress'); ?></a></p>
</article>

You need to look at this part:

href="<?php echo $recipe_url ;?>"  

The original code was:

href="<?php echo get_permalink() ?>"   

Now, I cannot get this url to appear on the link on the page...I even tried using some of the existing variables like $recipe_price, but nothing works

Any ideas what I might be doing wrong?

Thanks

share|improve this question
    
Sorry, what "page" do you want the link to show up on? It is hard to tell from your description. Given that the original code used get_permalink I am guessing you are trying to get the code to show up on the front end, but most of what you are talking about is back-end code. What outputs the link on the front? The disjointed nature of the way you posted the code makes it very hard to follow. –  s_ha_dum Sep 15 '13 at 16:46
    
Well, the the page I am referring to contains html and backend data as set in the code here. The link, for example, shows up on the page, as well as the layout of the gallery and its attributes - names, categories etc.The problem is that the variable is not defined on this page - The page contains a gallery preview of a bunch of posts, and in wordpress on the post page, you can set these variables as defined in the code here, and they get called onto the page. Problem is, if I echo the variables using javascript alert, the alert shows 'undefined'. –  DextrousDave Sep 16 '13 at 8:16
    
I am not trying to be difficult but telling me what the page contains does not tell me what, or where, the page is. I don't know if "backend data" means " data I am using on the backend" or "data I saved via the backend but am using eleswhere". I still don't know if you are having trouble with the front or the back end. If it is the front I don't know what code is causing trouble, and now you are talking about Javascript as well. –  s_ha_dum Sep 16 '13 at 14:03

1 Answer 1

up vote 1 down vote accepted

I suspect the issue is that $recipe_url is undefined in the portion you're trying to echo it. Can you post a link to the full code of recipe_options.php? Use pastebin or something.

Try:

href="<?php 
        $recipe_detail_xml = get_post_meta($post->ID, 'recipe_detail_xml', true);
        $cp_recipe_xml = new DOMDocument ();
        $cp_recipe_xml->loadXML ( $recipe_detail_xml );
        $recipe_url = find_xml_value($cp_recipe_xml->documentElement,'recipe_url');
 echo $recipe_url ;
?>"  
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.