• First of all this is a wonderful plugin, thank you.
    I am trying to figure out if it is possible to build a post type that will serve as a series of landing pages where the content is selected by post name.
    So the pages would be “built” by the editor inserting a series of post_name(s) for the content type
    My thought was that since this query works:

    <?php query_posts(‘name=1950s’ ); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1 class=”entry-title”>” rel=”bookmark”><?php the_title() ?></h1>
    <?php the_content()?>
    <?php endwhile; endif; ?>

    I could insert a custom field value in place of 1950s in this code

    <?php query_posts(‘name=1950s’ ); ?>

    Since this won’t work (on my localhost):

    <?php query_posts(‘name=<?php print_custom_field(‘lead_story’); ?>’ ); ?>

    Is there another way to make this work?

    https://www.ads-software.com/plugins/custom-content-type-manager/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter jeffmcnear

    (@jeffmcnear)

    Well this does work:
    ‘<?php $pdogzine = get_post_meta($post->ID, “lead_story”, $single=true); ?>
    <?php $pdogzineZZ = get_post_meta($post->ID, “page_one_column”, $single=true); ?>’
    ‘<?php query_posts(‘name=’. $pdogzine); ?>’
    ‘<?php if (have_posts()) : while (have_posts()) : the_post(); ?>’
    [title | excerpt | etc]
    ‘<?php endwhile; endif; ?>’
    ‘<?php query_posts(‘name=’. $pdogzineZZ); ?>’
    ‘<?php if (have_posts()) : while (have_posts()) : the_post(); ?>’
    [title | excerpt | etc]
    ‘<?php endwhile; endif; ?>’

    However there is still an issue if the custom field is unpopulated … then all posts will show

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Yes, you could do that, but it seems awkward — as you noticed, the ‘get_custom_field’ function needs to be called when a post is in context, otherwise it doesn’t know which post to pull the custom fields from.

    I’m not sure if I follow what you’re trying to do, but perhaps you could leverage this a bit more cleanly if you use the “Relation” custom fields (https://code.google.com/p/wordpress-custom-content-type-manager/wiki/Relation) ?

    Re query_posts, I got so sick of its syntax and caveats that I abandoned its use entirely and created my own db querying class for use in the CCTM (see GetPostsQuery https://code.google.com/p/wordpress-custom-content-type-manager/wiki/GetPostsQuery), but querying is only part of your problem here I think.

    You could create a series of pages (regular pages or some custom post type either way) and add a summarize_posts shortcode on them (see https://code.google.com/p/wordpress-custom-content-type-manager/wiki/summarize_posts_shortcode). Or you could add the GetPostsQuery PHP equivalent to corresponding the template file. You wouldn’t be defining the search results by post name per se (although you could), you would be defining it by modifying the query present in the shortcode.

    Hope something up there helps.

    Thread Starter jeffmcnear

    (@jeffmcnear)

    What I’m trying to do (and have working locally) is to use custom fields to create queries specific to pre-existing (default) posts, so that the editor can put into the custom field(s) the name(s) of posts and that will dynamically “build” the post name section of a post name specific query like this:
    “<?php query_posts(‘name=1950s’ ); ?>”
    If I set up a variable for the query like this:
    “<?php $variablename = get_post_meta($post->ID, “custom-field-id”, $single=true); ?>”
    The I can do this:
    “<?php query_posts(‘name=’ .$variablename); ?>”
    and from that query draw in the title, featured image, excerpt, etc

    As I understand it the relation fields are intended to build a series of links to other content, but not actually pull any of that content into the page…

    … with gratitude & great respect!

    Thread Starter jeffmcnear

    (@jeffmcnear)

    By the way I believe I got around the empty fields issue by appending this to the variable
    “if( empty( $variablename) ) : ?> echo “”;<?php endif;?>”

    So that the whole thing would read:
    “<?php query_posts(‘name=’ .$variablename);
    if( empty( $variablename) ) : ?> echo “”;<?php endif;?>”

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Relation fields store an id to the referenced post or page (or image). From there, the question I always get is “what do I with that number?” It’s a common need to look up the data from that related post (e.g. https://code.google.com/p/wordpress-custom-content-type-manager/wiki/FAQ#My_Image/Relation/Media_Field_Only_Shows_Numbers._WTF?!?). Specifically relevant to this is the get_post filter: https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_post_OutputFilter (which is just a wrapper around the GetPostsQuery class — see also https://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_post_complete for a simpler interface).

    You’re basically trying to do the same thing I think, but you’re referencing the post by name instead of by ID, and that’s much more fragile. The post ID will never change, whereas the name might, and that could break your site. I’m glad if you got something working there, I would rethink it a bit if it were me.

    E.g. if you have a relation field storing a reference to a parent page, and then you want the current page to list all the children of that referenced page, in your template could do something like this:

    $referenced_page_id = get_custom_field('my_related_page'); // relation field returns ID
    $args = array();
    $args['post_parent'] = $referenced_page_id;
    $Q = new GetPostsQuery();
    $results = $Q->get_posts($args);
    foreach ($results as $r):
    ?>
        <h2><?php print $r['post_title']; ?></h2>
        <p><?php print $r['post_content']; ?></p>
    ...etc...
    <?php
    endforeach;

    That example assumes you’ve structured your pages hierarchically so we can query using the “post_parent” field, but hopefully you can see the principle there.

    Re empty values: good. There’s also the “default” output filter for that (https://code.google.com/p/wordpress-custom-content-type-manager/wiki/default_OutputFilter) but it wouldn’t apply unless you were using the get_custom_field function.

    Thread Starter jeffmcnear

    (@jeffmcnear)

    I was wrong about the “if(empty” condition taking care of empty values. When there is no value my query spits out a ridiculously long series of posts which I suppose is because there is no filter being executed. If the field is populated by “.” everything is fine – I suppose since the query is coming back as empty. For some reason “if( empty( $variablename) ) : ?> echo “.”;<?php endif;?>” when I define the variable doesn’t work.

    I understand what you mean about the post names being unstable, but am leaning towards them since the ultimate site editor is more likely to be able to keep track of the names than the IDs.

    It sounds like I’ve missed some of the depth of your work in the relation area and should dig a little deeper to understand what can be done with it.

    I greatly appreciate your time, and want you to know that I find your plugin quite wonderful!

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    The “if(empty(…))” construct is very common in PHP, so it’s good to get used to it. It sounds like you might be running into some of the inanities of the quirky query_posts() function.

    Maybe you can wrap that call in its own if statement:

    <?php
    $variablename = get_post_meta($post->ID, "custom-field-id", true);
    if (!empty($variablename)) {
        query_posts('name=' .$variablename);
    }
    else {
        print 'Sorry, there are no results.';
    }
    Thread Starter jeffmcnear

    (@jeffmcnear)

    Thankyou … I’ll give it a try and let you know what happens!

    Hi Jeff,

    First of all apologies to reply here. I ran into this: https://www.ads-software.com/support/topic/plugin-jquery-accordion-menu-widget-peculiar-issue-in-chrome-safari?replies=2 issue mentioned by you and came to know that you managed to fix it. Since the thread was closed, I was not able to reply you there. Can you provide some more details as to how you managed to fix it. Any help from you is much appreciated.

    @fireproofsocks Apologies for replying here.

    Have a nice day!

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @rohan-k Per the forum welcome, if you need support for this plugin please start your own topic.

    https://www.ads-software.com/support/plugin/custom-content-type-manager#postform

    It’s the best way to get support for your problem. This topic is 6 months old and there have been changes to WordPress since then.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Using custom field values to build a directory page’ is closed to new replies.