Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • We’re having the same problem as djhsecondnature.

    We have a custom post type for ‘featured product’, which we’re linking to individual blog posts. Each blog post has a box at the bottom for featured product. When we preview a blog post before it’s published, the featured product isn’t shown. After the post is published, preview shows the featured post box, but not before, and our writers are unhappy because they’d like to be able to preview the featured product box before publishing the post.

    Can anyone help?

    Here’s the code:

    // add connection type
    function my_connection_types() {
    	p2p_register_connection_type( array(
    		'name' => 'posts_to_featured_products',
    		'from' => 'post',
    		'to' => 'featured_products'
    	) );
    }
    add_action( 'p2p_init', 'my_connection_types' );
    
    // add product box after content
    add_action('template_redirect', 'product_conditional_actions');
    function product_conditional_actions() {
    	if( is_single() && !is_singular( 'featured_products' ) ) {
    	add_action('genesis_after_post_content', 'add_featured_product_box');
    	}
    }
    
    function add_featured_product_box() {
    
    	// Find connected pages
    	$connected = new WP_Query( array(
    	  'connected_type' => 'posts_to_featured_products',
    	  'connected_items' => get_queried_object(),
    	  'nopaging' => true,
    	) );
    
    	// Display connected pages
    	if ( $connected->have_posts() ) :
    	?>
    	<div class="featuredproductteaser">
    		<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    
    				<?php $producturl=get_post_meta(get_the_ID(), 'product_url', true);
    					if ( $producturl ) { ?>
    
    						<?php if ( has_post_thumbnail() ) { ?>
    							<a href="<?php echo $producturl; ?>" target="_blank">
    								<?php the_post_thumbnail('featured-product-thumb'); ?>
    							</a>
    							<?php } ?>
    						<div class="copy">
    							<h2>Featured resource</h2>
    							<h3><a href="<?php echo $producturl; ?>" target="_blank"><?php the_title(); ?></a></h3>
    							<?php the_excerpt(); ?>
    							<p class="flink"><a href="<?php echo $producturl; ?>" target="_blank">Get it now</a></p>
    						</div>
    
    					<?php } else { ?>
    
    						<?php if ( has_post_thumbnail() ) { ?>
    							<a href="<?php echo $producturl; ?>" target="_blank">
    								<?php the_post_thumbnail('featured-product-thumb'); ?>
    							</a>
    							<?php } ?>
    						<div class="copy">
    							<h2>Featured resource</h2>
    							<h3><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></h3>
    							<?php the_excerpt(); ?>
    							<p class="flink"><a href="<?php the_permalink(); ?>" target="_blank">Get it now</a></p>
    						</div>
    
    				<?php } ?>
    
    		<?php endwhile; ?>
    	</div>
    	<?php
    	// Prevent weirdness
    	wp_reset_postdata();
    
    	endif;
    
    	}
    Thread Starter artemisian

    (@artemisian)

    OK, looks like this might explain it. Good to know.

    Sorry for multiple postings. I’m going to go away and be quiet now. 🙂

    Thread Starter artemisian

    (@artemisian)

    Ah!

    pluggable.php’s line 934 is in the wp_redirect section. And on my code, at line 178, is ‘wp_redirect( home_url() );’.

    I’ve just tried removing that, and now no error message. Which is brilliant!

    But I’d still like to understand what happened there, so if anyone can enlighten me, I’d really appreciate it!

    Thread Starter artemisian

    (@artemisian)

    New development – the problem has spontaneously resolved itself. Is it possible that some temporary change in our environment was causing it? Perhaps our hosting people were upgrading the php or something? Would love to hear any ideas anyone has.

    God bless you for figuring that out. It was driving me crazy!

    Thread Starter artemisian

    (@artemisian)

    Hey jceresini. My .htaccess just has the usual bit of WP generated code in:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    plus Options -Indexes, and some 301 redirects of old pages.

    After a little more experimentation, I’ve found that I only get the 404 if the link has a query string. If I go to:

    http://mydomain.com/cmd.php

    Then it redirects to 1ShoppingCart’s home page.

    If I try variations which ought to work, for example links of the form:

    http://mydomain.com/cmd.php?u=%5Burl%5D
    http://mydomain.com/cmd.php?af=%5Baffiliate code]
    http://mydomain.com/cmd.php?productid=%5Bproduct code]

    Then I get my WP 404.

    If I try a made-up query string on a real WP page, such as http://mydomain.com/contact/?madeup=4893574 then I get the page I’d expect (my contact page here). So *something* is happening, but I can’t figure out what. It seems unlikely that the cmd.php code is broken, as it’s just 1ShoppingCart’s standard code, which I’ve seen working perfectly on plenty of other sites. So what’s going on?

    Thread Starter artemisian

    (@artemisian)

    Hang on – this would do it, no?

Viewing 7 replies - 1 through 7 (of 7 total)