2

My page (outside the wordpress install) begins something like this:

global $wpdb, $wp_query; 
define('WP_USE_THEMES', false);
include_once 'word/wp-blog-header.php';

$args = array(
  'posts_per_page'  => 10,
  'post_type'       => 'post'
);
$queryObject = new WP_Query($args);

I start the loop like so:

<?php while (have_posts()): the_post(); ?>

In the loop I call this:

<?php the_post_thumbnail();?>

But nothing is returned.

print_r(get_post(4));

(Where 4 is the id of an attachment) also returns nothing.

Calling

<?php the_content(); ?>

echoes the post content, minus the gallery - which also doesn't get rendered, but the shortcode is removed.

Inside wordpress everything works fine, outside it seems that attachments are simply ignored. Why does this happen? Is there a workaround? Is there something wrong with my query?

.

.

.

I found an alternative solution to my original problem - using a subdirectory, but I still feel this is a valid question. The original is here:

I'm using the wordpress engine as a CMS for a website that can't be integrated into wordpress right now because of time constraints (but will be eventually), so I need to get hold of things like post thumbnails outside of the wordpress directory. I'm using the following to set up my loop:

global $wpdb, $wp_query; 
define('WP_USE_THEMES', false);
include_once 'word/wp-blog-header.php';
$args = array(
  'posts_per_page'  => 10,
  'post_type'       => 'leather_swatch'
);
$loop = new WP_Query($args);

if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post();

However, in index.php this works, but returns nothing in my external loop:

$thumb = get_post_thumbnail_id($post->ID);
echo '<img src="'.wp_get_attachment_url($thumb).'" />';

What I find really odd is that

print_r(get_post($thumb)); 

returns a post object inside the wordpress directory, but nothing in my custom loop - it doesn't recognise attachments. However I can still print out the content of my post type in the custom loop using the standard the_content() function.

Can anyone illuminate what's going on/how I might fix this? I don't really want to use custom meta data to replicate standard functionality.

  • That's a classical X/Y-Problem. Could you please explain why your site can't get integrated into WordPress? – kaiser Dec 17 '13 at 15:46
  • It's got a lot of custom javascript, as well as a home rolled CMS (which is very buggy, hence why I want to migrate to wordpress). It'll take longer than I've been allocated to do the integration right now, and what I'm attempting seemed like a decent stop-gap solution, as well as a way to start migration. That aside though, this seems like very odd behaviour for wordpress and I'd be interested to know more regardless. – Gaffen Dec 17 '13 at 15:58
  • Might this get you started? wordpress.stackexchange.com/a/112157/13676 – GhostToast Dec 17 '13 at 16:24
  • The problem isn't so much that I can't get the image from a URL, but moreso that I can't get the URL in the first place. Oddly wp_get_attachment_link() works, but that returns a link to the wordpress media page, whereas I need the image src. All attachments load fine inside the actual wordpress install, the problem only happens when I try to get the image src outside the main WP dir – Gaffen Dec 17 '13 at 16:32
1

Your older code seems to work just fine, if there were issues with it - something else caused them.

Your updated version seems to take a step back since your loop is written like main loop and is not using $queryObject that you set up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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