Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Can’t figure out error

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36389
    leehughes
    Member

    Hi,

    I’m using the following code to try and pull the post images from single posts and publish them on a page.

    function photos() {
    if (is_page('lee')) return;

    global $post;
    echo '
    ';
    $the_query = new WP_Query( array (
    'category_name' => 'prom',
    'numberposts' => 10 ) );

    for( $i = 0; $i <= $the_query->post_count; $i++ ):
    echo '
    ';
    $the_query->the_post();
    $image = get_post_meta( $post->ID, 'thesis_post_image', true );

    echo '';
    echo '';
    echo '
    ';
    echo '';
    the_title();
    echo '
    ';
    echo '
    ';
    endfor;

    echo '
    ';
    }
    add_action( 'thesis_hook_before_post', 'photo' );

    I’m getting the following error though http://the-ephemeral-project.com/lee/ I don’t know where I have gone wrong..

    Any advice?

    #95690
    Shebo
    Member

    in “add_action( ‘thesis_hook_before_post’, ‘photo’ );” you are “actioning” the function ‘photo’, instead of ‘photos’. the ‘add_action’ cannot find a function named ‘photo’ and as result it referring it as a string.

    change your function name or correct the callback name in the ‘add_action’ function to match your function.

    For example:

    function photos() {
    if (is_page('lee')) return;

    global $post;
    echo '
    ';
    $the_query = new WP_Query( array (
    'category_name' => 'prom',
    'numberposts' => 10 ) );

    for( $i = 0; $i <= $the_query->post_count; $i++ ):
    echo '
    ';
    $the_query->the_post();
    $image = get_post_meta( $post->ID, 'thesis_post_image', true );

    echo '';
    echo '';
    echo '
    ';
    echo '';
    the_title();
    echo '
    ';
    echo '
    ';
    endfor;

    echo '
    ';
    }
    add_action( 'thesis_hook_before_post', 'photos' );
    #95699
    leehughes
    Member

    D’oh! Sorry missed that. I have corrected that and the error has now gone but the post images are not showing.. hmm http://the-ephemeral-project.com/lee/

    #95770
    Shebo
    Member

    try to delete all the photos function and try just to throw an echo to the action. I don’t think that the ‘thesis_hook_before_post’ hook is working for you in this case, maybe u need another one.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.