Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WillBontrager

    (@willbontrager)

    Niranjan, perhaps something like this would work.

    [insert_php]
    $UserID = /* assign user id to variable $UserID */
    echo "<a href='https://www.google.com/src=$UserID'>Click here</a>";
    [/insert_php]

    CAUTION: I’m unsure what you mean by userid. In case you’re referring to the WordPress dashboard, please understand that anyone who is logged into the dashboard can use Insert PHP so long as it is installed and activated; thus, they can do anything PHP can do on a web page.

    Will

    Hello WillBontrager,

    Why function in anchor tag doesn’t work?
    I am trying to add “the_permalink” in anchor tag in while loop of my archive like page BUT its not working!

    Here is the code

    <ul class="products"> 
      [insert_php]
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => -1,
            'product_cat' => 'armour-suits-helmets'
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
    echo "<a href='".the_permalink()."'>Click here</a>";
            endwhile;
        }
        wp_reset_postdata();
    [/insert_php] 
    </ul>

    The above anchor tank suppose to show url like this

    Click Here

    BUT it shows this output instead

    https://demo.eliteimpexco.com/product/picklehaube-helmets/Click here

    Plugin Author WillBontrager

    (@willbontrager)

    The code looks OK to me and I don’t know why it publishes the URL as visible text. Strange that it does that. Something may be interfering.

    The only suggestion I have is to try temporarily deactivating other plugins to see if there’s interference from there.

    Will

    Hello WillBontrager,

    I did try your suggestion, here is what I did…

    1. Deactivate all plugins except “Insert PHP (Your Plugin)” AND “Woocommerce (Because I was querying its products)”.

    2. Apply wordpress default theme (Twenty Sixteen).

    3. Did Execute this simple code

      [insert_php]
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => -1,
            'product_cat' => 'armour-suits-helmets'
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post(); 
    		echo '<a href="'.the_permalink().'">'.the_title().'<br>';
            endwhile;
        }
        wp_reset_postdata();
    [/insert_php]

    OUTPUT

    
    https://localhost:85/media/product/product1/Product1
    https://localhost:85/media/product/product2/Product2
    https://localhost:85/media/product/product3/Product3
    https://localhost:85/media/product/product4/Product4
    

    Then I did one change in code. I did replace “the_permalink()” functions with static url (https://www.google.com) just for testing purpose. And I get this output

    
    Poduct1
    Poduct2
    Poduct3
    Poduct4
    

    Conclusion:

    When I did use “the_permalink()” function in anchor tag to get url dynamically then output got messy But when I did use static url instead of “the_permalink()” function then output was correct. But problem is I can’t use static url inside while loop!

    Please do a test by yourself to understand what I mean (in case if my explanation is not understandable).

    Any suggestions, what should I do?

    Plugin Author WillBontrager

    (@willbontrager)

    Those are some thorough tests, and I thank you.

    Several people have reported that Insert PHP and Woocommerce don’t play nice together.

    Something to try: In the while loop, populate an array. Below the while loop, use the array data to echo the links.

    I hope that will work for you.

    Will

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add user id to URL’ is closed to new replies.