• Resolved Marc

    (@standoutt)


    I’m attempting to make the following line of code work:

    <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts=5'.'&paged='.$paged); query_posts('category_name=
    	<?php
    	global $wp_query;
    	$postid = $wp_query->post->ID;
    	echo get_post_meta($postid, <strong>'BlogCat'</strong>, true);
    	?>
    '.'&paged='.$paged);
    ?>

    The BlogCat contains single quotes which are cancelling the other quotes and causing a syntax error. Cancelling the quotes (with a \)stops the error but the custom field is not called up. How do I fix this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    (@esmi)

    <?php $my_meta = "<strong>'BlogCat'</strong>"'
    $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts=5'.'&paged='.$paged); query_posts('category_name=
    	<?php
    	global $wp_query;
    	$postid = $wp_query->post->ID;
    	echo get_post_meta($postid, $my_meta, true);
    	?>
    '.'&paged='.$paged);
    ?>
    Thread Starter Marc

    (@standoutt)

    Using that gives me the following error:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/06/5371606/html/wp-content/themes/Srizzil2/blog.php on line 36

    esmi

    (@esmi)

    I’m not sure what you thought you were doing with the code but I thought it looked pretty mangled. There’s no category name being passed to the query; an extra opening <?php tag in the middle of the query arguments and other bits that make no sense at all. Best I can do is create 2 code snippets from it:

    <?php
    $temp = $wp_query;
    $wp_query = new WP_Query(); $wp_query->query('showposts=5'.'&paged='.$paged); ?>

    and:

    <?php
    $postid = $wp_query->post->ID;
    $my_meta = "<strong>'BlogCat'</strong>";
    echo get_post_meta($postid, $my_meta, true);
    ?>

    Michael

    (@alchymyth)

    you initial code is already totally broken:
    there is all this php meta stuff in the middle of query_posts() parameters;
    and you should either use WP_Query() or query_posts();

    try:

    <?php 	global $wp_query;
    	$postid = $wp_query->post->ID;
    	$blogcat = get_post_meta($postid, 'BlogCat', true);
    	?>
    $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('posts_per_page=5&paged='.$paged . '&category_name='.$blogcat);
    ?>
    Thread Starter Marc

    (@standoutt)

    Fantastic, that did the trick.

    What I am trying to do is make the template look for the category to include using the custom field. This way I can use one template for multiple pages with more focussed categories.

    There was a slight mistake, but I noticed it and corrected it. Here is the final working code.

    <?php 	global $wp_query;
    $postid = $wp_query->post->ID;
    $blogcat = get_post_meta($postid, 'BlogCat', true);
    $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('posts_per_page=5&paged='.$paged . '&category_name='.$blogcat);
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Single quotes within single quotes (PHP)’ is closed to new replies.