• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Trying to insert custom loop – News Child

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Trying to insert custom loop – News Child

This topic is: resolved

Tagged: loop, template page, WP_query

  • This topic has 1 reply, 1 voice, and was last updated 12 years, 5 months ago by Scottw.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 5, 2013 at 9:51 pm #18373
    Scottw
    Member

    Hi,

    I'm stuck and need help with getting a custom loop to display in the news theme (on a template page)  similar to what I do on my site at http://aviationglossary.com/

    I've tried a variety of hooks with no success.If I take the code out of the function the  content displays but not in the content area so the loop works but not in the function.

    What am I doing wrong? (I'm fairly new to PHP)

    Template
    get_col($wpdb->prepare("
    SELECT ID
    FROM $wpdb->posts
    WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
    ORDER BY $wpdb->posts.post_title",$first_char));

    if ($postids) {
    $args=array(
    'post__in' => $postids,
    'orderby' => 'title',
    'order' => 'ASC',
    'post_type' => 'post',//set this to custom post type if applicable
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );

    $my_query = null;
    $my_query = new WP_Query($args);

    if( $my_query->have_posts() ) {
    ?>

    have_posts()) : $my_query->the_post(); ?>
    <a href="" rel="bookmark" title=" definition">


    functions.php

    /* url paramter*/
    add_filter('query_vars', 'parameter_queryvars' );

    function parameter_queryvars( $qvars )// Function to be able to pick up mychar value at end of url
    {
    $qvars[] = 'mychar';
    return $qvars;
    }

    February 5, 2013 at 10:03 pm #18376
    Scottw
    Member

    Sorry, the code didn't display.. trying again

    <?php
    remove_action('genesis_loop', 'genesis_do_loop');
    //begin glossary code

    add_action( 'genesis_loop', 'custom_loop' );
    function custom_loop() {

    $first_char = $_GET["mychar"];// gets value of mychar in url
    //get all post IDs for posts beginning with letter equal to value of mychar in url , in title order,
    //display posts

    $postids=$wpdb->get_col($wpdb->prepare("
    SELECT ID
    FROM $wpdb->posts
    WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
    ORDER BY $wpdb->posts.post_title",$first_char));

    if ($postids) {
    $args=array(
    'post__in' => $postids,
    'orderby' => 'title',
    'order' => 'ASC',
    'post_type' => 'post',//set this to custom post type if applicable
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );

    $my_query = null;
    $my_query = new WP_Query($args);

    if( $my_query->have_posts() ) {
    ?>

    <h3> <?php echo 'Aviation Definitions beginning with the letter '. strtoupper($first_char);?>
    </h3><?php
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?> definition"><?php the_title();

    ?></a>
    <?php

    endwhile;

    } else
    {
    echo 'Sorry, no definitions found beginning with the letter '. strtoupper($first_char) . ', How about adding one?'; ?><?php
    }

    wp_reset_query(); // Restore global post data stomped by the_post().
    }
    } //end glossary

    genesis();

    ?>

     

    Functions.php file

    /* url paramter*/
    add_filter('query_vars', 'parameter_queryvars' );

    function parameter_queryvars( $qvars )// Function to be able to pick up mychar value at end of url
    {
    $qvars[] = 'mychar';
    return $qvars;
    }

     

     

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble