• Resolved johndoe01

    (@johndoe01)


    Greetings.
    After styling the ad creation form, and select the payment option, as soon as I go to preview throws me a 404 error.
    Even with the override template turned off, the error the same way.
    WP Debug set on true does not throws me any information.

    Site is still on local. Even i added an add-preview.php with a copy of single.php and remains the same.

    Thanks for any help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    this might be due to some field name, for example if a field name matches a taxonomy name or some WP query var the WordPress router might interpret the variable as a part of URL and throw a 404 error.

    Please try using the default [adverts_add] form, enter only required information submit it and see if the 404 error still shows? If it does not then the problem is with one of the field names. One solution would be to prefix the custom field names so they do not conflict with the WP router (to do that you would need to delete existing custom fields and recreate them as it is not possible to change the field names).

    If this will not help it would be great if you could send me a link to a page where you are having this problem so i can take a look at it.

    Thread Starter johndoe01

    (@johndoe01)

    OK, since I tried the [adverts_add] unmodified, the custom fields are still summoned, from functions.php. First I’ll disable all custom fields and then I’ll check field by field to find the conflicting one.

    I have uploaded the site but i need to ask permission to my customer since has a barrier and issues with Google Chrome (unrelated to WPAdverts). If the problem persists and client does not allow me to give URL I’ll show you a video soon.

    Thread Starter johndoe01

    (@johndoe01)

    Greetings.
    I debugged the fields and i found the culprit. The “Year” field. As soon as i changed the field the form got unstucked…
    …but now i have another problem.
    I had a custom add-preview.php based on the template’s single.php but it throws a time out error. As soon as i remove the call from functions, it works but shows under the single.php from the plugin.

    I have this call from functions.php

    add_action("adverts_template_load", "previa_aviso");
    function previa_aviso( $tpl ) {
        // $tpl is an absolute path to a file, for example
        // /home/simpliko/public_html/wp-content/plugins/wpadverts/templates/list.php
        
        $basename = basename( $tpl );
        // $basename is just a filename for example list.php
         
         if( $basename == "add-preview.php" ) {
            // return path to list.php file in custom-list-template directory
            return dirname( __FILE__ ) . "/add-preview.php";
         } else {
            return $tpl;
         }
    }

    This is my add-preview.php

    <?php get_header(); ?>
    <main id="singular type-page">
    <article class="block container "id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'entry' ); ?>
    <?php //the_content(); ?>
    <?php include apply_filters( "adverts_template_load", get_template_directory_uri().'/single-advert.php' ); ?>
    
    <hr/>
    
    <form action="" method="post" style="display:inline">
        <input type="hidden" name="_adverts_action" value="" />
        <input type="hidden" name="_post_id" id="_post_id" value="<?php echo esc_attr($post_id) ?>" />
        <input type="hidden" name="_post_id_nonce" id="_post_id_nonce" value="<?php echo esc_attr($post_id_nonce) ?>" />
        <input type="submit" value="<?php _e("Edit Listing", "wpadverts") ?>" style="font-size:1.2em" class="adverts-cancel-unload" />
    </form>
    
    <form action="" method="post" style="display:inline">
        <input type="hidden" name="_adverts_action" value="save" />
        <input type="hidden" name="_post_id" id="_post_id" value="<?php echo esc_attr($post_id) ?>" />
        <input type="hidden" name="_post_id_nonce" id="_post_id_nonce" value="<?php echo esc_attr($post_id_nonce) ?>" />
        <input type="submit" value="<?php _e("Publish Listing", "wpadverts") ?>" style="font-size:1.2em" class="adverts-cancel-unload" />
    </form>    
    <?php if ( comments_open() && ! post_password_required() ) { comments_template( '', true ); } ?>
    <?php endwhile; endif; ?>
        </article>    
    <footer class="footer">
    <?php get_template_part( 'nav', 'below-single' ); ?>
    </footer>
    </main>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    And the error that throws me is this

    I could remove the call from the functions.php to the template’s add-preview.php but that view doesn’t show the custom fields (but they appear in the final ad).

    First part… https://imgur.com/9no2OU4
    Second part, the end of that same screen https://imgur.com/RYFgw3Y

    I’m not sure if making an instance of single advert in another layout might work might work but i’m lost in order to see the custom fields on the preview.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    most likely the problem is the code here

    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'entry' ); ?>
    <?php //the_content(); ?>
    

    you are executing the_content filter inside the_content filter which causes an infinite loop.

    Thread Starter johndoe01

    (@johndoe01)

    Greetings. Well It now changed a problem with another.

    Now doesn’t get hung up but throws me the following error:

    View post on imgur.com

    Since i commented the mentioned lines and subsequent closings i debugged the single-advert file commenting such lines as well but with no result. However the single advert is working fine under those commented lines when viewing any ad.

    Line 6 In add-preview is at this moment:
    <?php include apply_filters( "adverts_template_load",'/single-advert.php' ); ?>

    I copied as is from the template:
    <?php include apply_filters( "adverts_template_load", ADVERTS_PATH . 'templates/single.php' ); ?>
    And throws me the default view (no custom fields).

    I remove the adverts path:
    <?php include apply_filters( "adverts_template_load", '/single.php' ); ?>
    Same result, default layout.

    But if I remove/rename single-advert.php to ensure that the file is being called
    Throws me the same.

    And adding this:
    <?php include apply_filters( "adverts_template_load",get_template_directory_uri().'/single-advert.php' ); ?>
    becomes the same result.

    Basically behaves like the file is not there when it is.

    The finction that calls add-preview.php is this one

    add_action("adverts_template_load", "previa_aviso");
    function previa_aviso( $tpl ) {
        // $tpl is an absolute path to a file, for example
        // /home/simpliko/public_html/wp-content/plugins/wpadverts/templates/list.php
        
        $basename = basename( $tpl );
        // $basename is just a filename for example list.php
         
         if( $basename == "add-preview.php" ) {
            // return path to list.php file in custom-list-template directory
            return dirname( __FILE__ ) . "/add-preview.php";
         } else {
            return $tpl;
         }
    }

    Looks like i fell on a Dead End.

    Plugin Author Greg Winiarski

    (@gwin)

    The error suggests that the file name passed to “include” is empty, if the file would not exist then you would see a different error message.

    My guess is that the previa_aviso() function somehow returns an empty value.

    Change your code to this

    
    <?php 
    $file = apply_filters( "adverts_template_load", ADVERTS_PATH . 'templates/single.php' );
    var_dump( $file );
    include $file;
    

    This will show you what value does the $file variable store it should be a path to a file, but if i am guessing correctly it will be either empty string or null.

    Thread Starter johndoe01

    (@johndoe01)

    Greetings. Well at first, it threw me Null as you said.

    <?php $file = apply_filters( "adverts_template_load", "" );
    var_dump( $file );
    include $file; ?>  

    Then i removed the file destination, leaving only the quotes and threw me this:

    View post on imgur.com

    So i did a lot of attempts and i had to rewrite the previa_aviso()function like this:

    
    add_action("adverts_template_load", "previa_aviso");
    function previa_aviso( $route ) {
        // $tpl is an absolute path to a file, for example
        // /home/simpliko/public_html/wp-content/plugins/wpadverts/templates/list.php
        
        $basename = basename( $route );
        // $basename is just a filename for example list.php
         
         if( $basename == "add-preview.php" ) {
            // return path to list.php file in custom-list-template directory
             $route = get_template_directory()."/add-ad-preview.php";
            return  $route;
         } else {
            return $route;
         }
    }

    And then the redirection went correctly.

    <?php 
    $file = apply_filters( "adverts_template_load", get_template_directory() . '/single-demo.php' );
    var_dump( $file );
    include $file; ?> 

    And i had to do an instance of the single advert without the post_id() variable set.

    View post on imgur.com

    I have to debug some info but what i needed to do was set.

    Thanks for the help and leads.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Creating ad – Preview throws 404’ is closed to new replies.