Marketpress affiliate external links not working on all products

Hi there,

We’ve noticed that our most recent products, plus any new ones that we add, no longer have properly working External Links! We’re using an affiliate products-only set up, and I’m retrieving the external links in PHP using get_post_meta(). On about half of the products in our catalog, the external link returned is empty, even though on the Product Edit screen, we can see the saved value correctly.

I’ve tried disabling themes and plugins, no good, and my searching has come up empty. I’m stumped on this one.

Thank you!

  • Tyler Postle
    • Recruit

    Hey roundhouseguys,

    Could you grant support access and provide the name or a link to a product where it’s working and a product where it’s not? Then I can have a closer look. This is the first time I’ve heard of an issue like this.

    You can grant support access via WPMU DEV > Support > Support Access > Grant Access.

    Look forward to hearing back!

    Cheers,

    Tyler

  • roundhouseguys
    • The Incredible Code Injector

    Hey Tyler,

    Totally forgot to enable support, thought I’d done it. Sorry, enabled now!

    Easiest for you to see (since we’re not using single product pages) is to head to .

    WORKING: Pink Pineapple Print

    NOT WORKING: The Hungover Cookbook (Or anything that appears above “Pink Pineapple Print” on the desktop view of the site on that page)

    Thank you!

  • Sajid
    • DEV MAN’s Sidekick

    Hi @roundhouseguys,

    Hope you are doing good today :slight_smile:

    Since, I can see the link is working on product single page of MarketPress so it appears that there must be something wrong with your code.

    Would you mind sharing the code here, if its a template then it would be great if you share the whole file so I can test by using it as it is on my own site, this will help me figure this out quickly :slight_smile:

    Cheers, Sajid

  • roundhouseguys
    • The Incredible Code Injector

    Hey Sajid,

    Thanks for jumping on, hope you’re well!

    Here’s the very simple code pulled in by the page template. It’s been working fine (and is working for many items on the page, especially it seems ones older than a couple of weeks), but all of a sudden has stopped working.

    Here’s the template part:

    <?php
    $feat = get_post_meta( $post->ID, '_grid-featured', true );
    $external = get_post_meta( $post->ID, 'mp_product_link', true );
    $postbox = ( $feat == 'yes' ) ? 'post-box-feat' : 'post-box';
    ?>

    <?php if ( $external ) : ?>
    <a class="shop-grid-link" href="<?php echo $external; ?>" target="_blank">
    <?php endif; ?>

    <article id="post-<?php the_ID(); ?>" <?php post_class( "$postbox shopgrid-item" ); ?>>
    <header class="entry-header">
    <?php the_post_thumbnail( 'medium' ); ?>

    <div class="shop-title">
    <h2 class="entry-title"><?php the_title(); ?></h2>
    </div>
    </header><!-- .entry-header -->

    <footer class="entry-meta">
    <?php edit_post_link( __( 'Edit', 'rhd' ), '<span class="edit-link">', '</span>' ); ?>
    </footer><!-- .entry-meta -->
    </article><!-- #post -->

    <?php if ( $external ) : ?>
    </a>
    <?php endif; ?>

    Thank you!!

  • Sajid
    • DEV MAN’s Sidekick

    Hi @roundhouseguys,

    Thanks for posting the code here.

    What loop you are using here ? Is it default while loop or foreach loop with setup post data ?

    Please post the code of parent page also here, so I can take a closer look.

    Also try to replace the $post->ID with get_the_ID().

    Hope that helps :slight_smile:

    Cheers, Sajid

  • roundhouseguys
    • The Incredible Code Injector

    Hey Sajid,

    The loop is a custom WP_Query…here’s the loop template:

    <div id="content" role="main">

    <?php rhd_grid_sizers(); ?>

    <?php $store_query = new WP_Query( 'post_type=product&posts_per_page=-1' ); ?>
    <?php if ( $store_query->have_posts() ) : ?>
    <?php while ( $store_query->have_posts() ) : $store_query->the_post(); ?>

    <?php
    $feat = get_post_meta( get_the_ID(), '_grid-featured', true );
    $postbox = ( $feat == 'yes' ) ? 'post-box-feat' : 'post-box';
    $external = get_post_meta( get_the_ID(), 'mp_product_link', true );
    ?>

    <?php if ( $external ) : ?>
    <a class="shop-grid-link" href="<?php echo $external; ?>" target="_blank">
    <?php endif; ?>

    <article id="post-<?php the_ID(); ?>" <?php post_class( "$postbox shopgrid-item" ); ?>>
    <header class="entry-header">
    <?php the_post_thumbnail( 'medium' ); ?>

    <div class="shop-title">
    <h2 class="entry-title"><?php the_title(); ?></h2>
    </div>
    </header><!-- .entry-header -->

    <footer class="entry-meta">
    <?php edit_post_link( __( 'Edit', 'rhd' ), '<span class="edit-link">', '</span>' ); ?>
    </footer><!-- .entry-meta -->
    </article><!-- #post -->

    <?php if ( $external ) : ?>
    </a>
    <?php endif; ?>

    <?php endwhile; ?>
    <?php endif; ?>

    </div><!-- #content -->

    Here’s the entire code snippet…I’ve put the pieces of the template together for easier reading, so you can see the whole thing together instead of get_template_part( ‘content’, ‘shop-grid’ ), so you won’t have to flip back and forth. I’ve verified that using the code this way doesn’t change or fix the behavior.

    Sorry, I should also mention that rhd_grid_sizers() simply echoes static HTML, so can be ignored.

    And using get_the_ID() instead of $post->ID didn’t help, sadly!

    Thank you!

  • Sajid
    • DEV MAN’s Sidekick

    Hi @roundhouseguys,

    Hope you are doing good today :slight_smile:

    Here are two methods:

    Method # 1

    Try to replace the below code:

    $external = get_post_meta( get_the_ID(), '$external = get_post_meta( get_the_ID(), ‘external’, true );`

    ‘, true );`

    With this one:

    $external = get_post_meta( get_the_ID(), 'external', true );

    Method # 2

    Load the product with following code in start of the loop.

    $product = new MP_Product( $post->post_id );

    And then replace following code with:

    $external = get_post_meta( get_the_ID(), 'mp_product_link', true );

    With this one:

    $external = $product->url( false );

    Well, if still no luck then please send in FTP and WordPress login details using private contact form in following format.

    Subject: “Attn: Sajid Javed”

    -WordPress admin username

    -WordPress admin password

    -login url

    -FTP credentials (host/username/password)

    -link back to this thread for reference

    -any other relevant urls

    Select “I have a different question” for your topic – this and the subject line ensure that it gets assigned to me :slight_smile:

    https://wpmudev.com/contact/

    Take care and have a nice day :slight_smile:

    Cheers, Sajid

  • roundhouseguys
    • The Incredible Code Injector

    Hey Sajid,

    Before I go through all of the steps of emailing for deeper-level support with you, can you clarify Method #1? The code you’d have me replace doesn’t make any sense. It’s formatted strangely in your post, but if I understand correctly, you’d like me to replace the ‘mp_product_link’ key in the get_post_meta() function, but ‘external’ doesn’t seem to be an existing meta key, and no posts or products have any values associated with that key. Can you explain Method #1 again?

    Method #2 did not work, since $product->url ( false ) returns the single product’s permalink, which we do not want. We’re trying to link to an external source, not to the single product page.

  • roundhouseguys
    • The Incredible Code Injector

    Hey again Sajid,

    Looks like I got it working! Your “Method #1” which didn’t make sense led me to examine the MP_Product class in the plugin files, and I found that the new meta key for the external product link is now ‘external_url’, not ‘external’ and no longer ‘mp_product_link’.

    I wish you guys had some better documentation (or else, easier to find documentation) that tells your users when indices and keys change like this—it costs us hours of work, and this is information that should be available.

    Thanks!

  • Sajid
    • DEV MAN’s Sidekick

    Hi @roundhouseguys,

    Hope you are doing good today :slight_smile:

    I am glad to know you have figured it out and sorry for your waste of time. We have revamped the MarketPress plugin from 3.x, we have updated the documentation and still working on better API documentation that will be available soon.

    Thanks for suggestion and your time :slight_smile:

    Cheers, Sajid