• zentode

    (@zentode)


    I am attempting to use this snippet of code in single post.

    <ul>
    <?php global $post;
    $myposts = get_posts('numberposts=100&offset=0&order=ASC&orderby=post_title&category=24');
    foreach($myposts as $post) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    I have issues due to limited mental capacity and old age.

    The above works but, I need to list only the chidren of the current posts category. I was able to do that but, I only want one level down.

    I also desired to have my posts in multiple categories. So re-assigning tons of cats is not an option. I also messed with tags to no avail.

    My solution is to use custom fields to get the results I need.

    Say I have a custom field key “schematics” with a value of “amplifier”. I have several posts with the same combination. Enter them into specific posts based on the list result I want.

    How can I use the above code, (or any code) to list only the posts with the same custom field combinations, but wait….. based on the current post?

    The problem I am having with categories is that all the children list as well as their children when I use:

    if (is_category()) {
    global $wp_query;
    $cat_obj = $wp_query->get_queried_object();
    $cat_id = $cat_obj->term_id;
    }

    to define category=$cat_id

    I figured that’s what custom fields may be used for.

    So, what if I titled the post “Schematic” and if the title matches the custom field key (???) it would list all posts with the key “schematic”? I may need to force lowercase before the match as well? (I do a little php and perl javascript). This would allow me to title my posts according to the custom field name in order to set up the match for the query. Right?

    In addition, how could I list only those with the custom field combo key=schematics value=amplifier. (“either” “or” or “both”)

    This would allow me to show something like:
    (these all represent individual posts with the wp generated table of contents below each post.)
    ——————
    (post title) Schematics

    description yada yada

    toc Schematics
    1- Amplifiers
    2- Test Gear
    3- Consumer
    4- High Voltage Generators
    ———————-
    select number 1 for instance goes to post
    ——————-
    (post title) Amplifiers

    -description yada yada

    -toc Amplifiers
    -1- Tube
    -2- Solid State
    -3- Hybrid
    ———————
    select number 3
    ——————-
    –Hybrid

    –description yada yada

    –toc Hybrid
    –1- Mosfet Power stage
    –2- Mosfet Preamp Stage
    –3- Bipolar Transistors
    –4- IC Stages
    ———————-
    select number 1
    ——————-
    —Mosfet Power Stage

    —description yada yada

    —toc Mosfet Power Stage
    —1- 30 watt
    —2- 50 Watt
    —3- 100 Watt
    —4- 200 Watt
    ———————-
    select number 3
    ——————-
    —-100 Watt Hybrid Tube Amplifier

    —-the schematic and build info

    —-toc Shematics (or I can just mod a breadcrumb this part here)
    —-1- Amplifiers
    —-2- Hybrid
    —-3- Mosfet Power Stage
    —-4- 100 Watt

    I did read all the related documention but, this is beyond my ability. I’m an amp designer not a coder. 😉

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter zentode

    (@zentode)

    A small mistake that could add much confusion – In the last level, the post title should be “100 Watt” as listed in the toc (table of contents) of the above level. Not 100 Watt Hybrid Tube Amplifier. Sorry.

    ivovic

    (@ivovic)

    you’re over-thinking this….

    if you want to list posts from only the next child down (out of perhaps multiple categories, but only the first child of each category….

    then you should limit the children you gather… by using something like this:

    $children = get_categories('child_of='.$cat);
    $foreach ($children as $subcat) {
      $parents = explode('|',get_category_parents($subcat,false,'|'));
      if ($parents[2] == "") { ?>

    so, for each of the children categories… test to see if they have a grandparent. if they do NOT have a grandparent (just a parent) then they are a child (not a grandchild).

    Grandchildren will just be skipped as part of the loop.

    I hope that makes sense.

    Thread Starter zentode

    (@zentode)

    Thannk you much. I tried:

    <?php
    $children = get_categories('child_of='.$cat);
    $foreach ($children as $subcat) {
    $parents = explode('|',get_category_parents($subcat,false,'|'));
    if ($parents[2] == "") {
    echo "<li><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></li>";}
    ?>
    <?php endforeach; ?>

    and some slight variations but, I just get Parse error unexpected T_AS

    I am no coder.

    I am putting the above right after:
    <?php the_content(__('Read the rest of this entry &raquo;','wp_multiflex')); ?>
    in single-post.

    I also tried substituting $cat with $cat_id after using the routine in the top of my last post. I have spent two weeks trying to figure this out. I just want to share my schematics and ideas in an easy to navigate method. I really need more help.

    I forgot to mention I am running wp2.5 on a clean install minus all my data.

    I really appreciate your suggestion though.

    Thread Starter zentode

    (@zentode)

    I really need a soulution. Can someone show me by example how to list all posts that have the custom field key “schematics” value =1 in single.php? I have tried many things including:

    <?php get_header(); ?>
    <?php $query= "
    $toc = $wpdb->get_results( $query );
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 24
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'meat'
    ORDER BY $wpdb->postmeta.meta_value ASC
    ";
    
    $toc = $wpdb->get_results( $query );
    ?>

    at the very top of the template file then attempting to display ANYTHING AT ALL under the_content
    <?php echo "$toc"; ?>

    I did get the word Array to appear!

    I am at my wits end. There must be a simple solution. I have tried all examples and many plugins and none return desired results. My theme is 2.5 compatible. The closest I got was using the in-series plug in which is awesome but, only works on the last two levels of my needed example output above (by design).

    I just need a way to display my data kind of like like a recipe book. I am sure that has been done a million times already. I cannot use categories, that will not work with the same “schematic (or recipe)” in different categories.

    Using a custom field, I can assign each related post to a single common name or number. Allowing me to list their permalinks in a table of contents format. Right?????????

    Kind of like:

    foreach post in current posts lowest category
    if posts custom key = "this" then print its permalink
    end foreach loop

    No parents, children or grandchildren come into play there right? Except getting only posts from its lowest category instead of all of its categories to speed things up?

    Just the lowest category of the post so all posts in higher cats do not need to be queried?

    Sounds easy but, after over 100 hours (easy) of tying I am going nuts!!

    This is not a money making thing. It is for me and my kids. For game cheats, schematics, model airplane plans, guitar tab and such things.

    If I did not mention, I got this to work to a point:

    <ul>
    <?php global $post;
    $myposts = get_posts('numberposts=100&offset=0&category=24');
    foreach($myposts as $post) : ?>
    <?php echo c2c_get_custom('schematics'); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>

    but, it lists children. If I could mod that code to only list the posts that have the custom field key “schematics” value=”1″ I would be done!

    current mood == Frustrated….

    Sorry so long winded. I desire to make my request a clear as possible.

    My family and I appreciate all input and assistance to a great degree.

    Thread Starter zentode

    (@zentode)

    I went over Ivovics code again and I don’t understand why it errors on the foreach line. I compared to other similar snippets and all seems well.

    Here is the code from Ivovic I am attempting to use in my single.php.

    <?php
    $children = get_categories('child_of='.$cat);
    $foreach ($children as $subcat) {
    $parents = explode('|',get_category_parents($subcat,false,'|'));
    if ($parents[2] == "")?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    It makes sense. Why does it crash? Help?

    And this code:

    <?php
    if($post->post_parent)
    $children = get_posts("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = get_posts("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    Just returns the word “Array”???

    HHEELLLLPPP! It’s for a worthy non profit cause!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘List specific custom fields in a post that match post title’ is closed to new replies.