Forum Replies Created

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter shoxt3r

    (@shoxt3r)

    Thanks for the feedback.
    However – I’ve found the issue in the meantime. Just to feedback for anyone else coming across this thread – turns out I made the rookie error of not adding “has_archive” => true to the arguments list when the post type is registered. Oops!

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok, so just to feedback for anyone else coming across this thread – turns out I made the rookie error of not adding “has_archive” => true to the arguments list when the post type is registered within the “class-post-types.php” file. Oops!

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok thanks Tijmen – I’ve sent a support ticket along with a WeTransfer link containing the zip file (I couldn’t attach it to the message itself as it wasn’t an accepted format).

    Many thanks for your help with this!

    Thread Starter shoxt3r

    (@shoxt3r)

    Hi there,

    The error is appearing on a custom “404.php” page I created, so it’s just a text-based message for now but isn’t a “server error” if that helps?

    Thanks for recommending the Query Monitor plugin – I’ve loaded it up and navigated to the “Cinema” Post Type page and selected “Main Query” from the “Caller” dropdown and this is what I see:

    https://pasteboard.co/KfrPuwn.png

    One thing I have noticed is that if I change the page name of “single-cinema.php” to “single-cinemas.php”, then the individual cinema page breaks – but still neither my “archive-cinema.php” and “page-cinema.php” pages work, they just 404. I was hoping it was something as simple as that before I posted as I’ve done that mistake before but no such luck.

    Would it help if I posted a link to download the project?

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok I think the above was a red herring since I wrote back to the plugin developer and he came back with the following:

    There’s this code in the class-frontend.php that creates the default front-end template. But there’s nothing else in the code that forces a specific template.

    But it shouldn’t run if you created a single-your-cpt.php.

    I’ve now gone back through a fresh version of the plugin and replaced anything related to “store” or “stores” with “cinema” or “cinemas”. However, while going through the “class-post-types.php” file I spotted it registers a post type using the following code:

                // The arguments for the cinema post type.
                $args = apply_filters( 'wpsl_post_type_args', array(
                        'labels'              => $labels, 
                        'public'              => $public,
                        'exclude_from_search' => $exclude_from_search,
                        'show_ui'             => true,
                        'menu_position'       => apply_filters( 'wpsl_post_type_menu_position', null ),
                        'capability_type'     => 'store',
                        'map_meta_cap'        => true,
                        'rewrite'             => $rewrite,
                        'query_var'           => 'cinema',
                        'supports'            => array( 'title', 'editor', 'author', 'excerpt', 'revisions', 'thumbnail' ),
                        'show_in_rest'        => $this->maybe_show_in_rest()
                    )
                );
    
                register_post_type( 'cinema', $args );

    Note that here, it’s registering my new post type of “cinema”.

    Now, I don’t know whether the rewrite is coming from the WP Store Locator Settings, or whether the following code I have in my “apex-post-types.php” file, but the “cinema” slug now redirects to “cinemas” which is what I want (I would guess my code in “apex-post-types.php” is redundant to be honest).

     function wp1482371_custom_post_type_args( $args, $post_type ) {
                if ( $post_type == "cinema" ) {
                    $args['rewrite'] = array(
                        'slug' => 'cinemas'
                    );
                }
            
                return $args;
            }
            add_filter( 'register_post_type_args', 'wp1482371_custom_post_type_args', 20, 2 );

    Now I’m in a situation whereby the “single” pages are working, but I still can’t get an archive or regular page to show, despite calling it “archive-cinema.php” and “page-cinema.php” to match the new post type registered via “class-post-types.php”.

    Any thoughts why the main page may not be loading? I just get a 404 when I try to visit /cinemas (which is rewritten from /cinema, remember :))

    Would it help to do a site export so you can see for yourself what the issue may be?
    I’ve done several Permalink saves and nothing seems to resolve it.

    • This reply was modified 4 years, 10 months ago by shoxt3r.
    Thread Starter shoxt3r

    (@shoxt3r)

    Ok so I’ve now gone back through a fresh version of the plugin and replaced anything related to “store” or “stores” with “cinema” or “cinemas”. However, while going through the “class-post-types.php” file I spotted it registers a post type using the following code:

                // The arguments for the cinema post type.
                $args = apply_filters( 'wpsl_post_type_args', array(
                        'labels'              => $labels, 
                        'public'              => $public,
                        'exclude_from_search' => $exclude_from_search,
                        'show_ui'             => true,
                        'menu_position'       => apply_filters( 'wpsl_post_type_menu_position', null ),
                        'capability_type'     => 'store',
                        'map_meta_cap'        => true,
                        'rewrite'             => $rewrite,
                        'query_var'           => 'cinema',
                        'supports'            => array( 'title', 'editor', 'author', 'excerpt', 'revisions', 'thumbnail' ),
                        'show_in_rest'        => $this->maybe_show_in_rest()
                    )
                );
    
                register_post_type( 'cinema', $args );

    Note that here, it’s registering my new post type of “cinema”.

    Now, I don’t know whether the rewrite is coming from the WP Store Locator Settings, or whether the following code I have in my “apex-post-types.php” file, but the “cinema” slug now redirects to “cinemas” which is what I want (I would guess my code in “apex-post-types.php” is redundant to be honest).

            function wp1482371_custom_post_type_args( $args, $post_type ) {
                if ( $post_type == "cinema" ) {
                    $args['rewrite'] = array(
                        'slug' => 'cinemas'
                    );
                }
            
                return $args;
            }
            add_filter( 'register_post_type_args', 'wp1482371_custom_post_type_args', 20, 2 );

    Now I’m in a situation whereby the “single” pages are working, but I still can’t get an archive or regular page to show, despite calling it “archive-cinema.php” and “page-cinema.php” to match the new post type registered via “class-post-types.php”.

    Any thoughts why the main page may not be loading? I just get a 404 when I try to visit /cinemas (which is rewritten from /cinema, remember :))

    Would it help to do a site export so you can see for yourself what the issue may be?
    I’ve done several Permalink saves and nothing seems to resolve it.

    • This reply was modified 4 years, 10 months ago by shoxt3r.
    • This reply was modified 4 years, 10 months ago by shoxt3r. Reason: Added detail about which version of plugin amended
    Thread Starter shoxt3r

    (@shoxt3r)

    I should also point out that I’ve done a fresh install of the plugin and used the following details within the plugin settings:

    Store slug: “shop”
    Category slug: “all-shops”

    I’ve then registered a new CPT using the following:

        register_post_type('wpsl_stores', array(
            'show_in_rest' => true,
            'supports' => array('title', 'excerpt'),
            'rewrite' => array('slug' => 'shop'),
            'has_archive' => true,
            'public' => true,
            'labels' => array(
                'name' => 'Shops',
                'add_new_item' => "Add New Shop",
                'edit_item' => "Edit Shop",
                'all_items' => "View All Shops",
                'singular_name' => 'Shop'
            ),
            'menu_icon' => 'dashicons-location-alt'
        ));
    

    However, it’s still not possible to use a custom page template it seems.

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok, so I wrote on the WordPress forums and they came back with the following:

    `I suspect the plugin is forcing a specific template through the “template_include” filter. It’s a common technique, but I’m only speculating as it relates to that specific plugin. If this is indeed what the plugin does, you can override the plugin’s template choice with your own by hooking the same filter, but adding with a larger priority number so your callback’s template selection has the final say.

    Almost all requests go through this filter. Be sure you only alter the template of the specific page you wish to target. The returned value is immediately included by WP, so you should return a complete path to the desired template.

    Your callback isn’t given much context, but the various is_*() functions like is_single() will work. You can examine the query vars used through the global $wp_query object properties. If you are targeting a single page, you can get its ID through get_queried_object_id().`

    I had a search for “template_include” but it isn’t listed in any of the plugin’s files.

    After searching for the term “template” I did come across the following code, however, but I believe this only refers to the following documentation – I’m unsure if it’s even relevant?

    public function show_template_options() {
                
                global $wpsl_settings;
                
    			$dropdown = '<select id="wpsl-store-template" name="wpsl_ux[template_id]" autocomplete="off">';
    
                foreach ( wpsl_get_templates() as $template ) {
                    $template_id = ( isset( $template['id'] ) ) ? $template['id'] : '';
                    
    				$selected = ( $wpsl_settings['template_id'] == $template_id ) ? ' selected="selected"' : '';
    				$dropdown .= "<option value='" . esc_attr( $template_id ) . "' $selected>" . esc_html( $template['name'] ) . "</option>";
                }
    			
    			$dropdown .= '</select>';
    			
    			return $dropdown;            
            }

    https://wpstorelocator.co/document/load-custom-store-locator-template/

    Any thoughts please?

    Thread Starter shoxt3r

    (@shoxt3r)

    I had a search for “template_include” but it isn’t listed in any of the plugin’s files.

    After searching for the term “template” I did come across the following code, however, but I believe this only refers to the following documentation – I’m unsure if it’s even relevant but will write back to the plugin creator and find out.

          public function show_template_options() {
                
                global $wpsl_settings;
                
    			$dropdown = '<select id="wpsl-store-template" name="wpsl_ux[template_id]" autocomplete="off">';
    
                foreach ( wpsl_get_templates() as $template ) {
                    $template_id = ( isset( $template['id'] ) ) ? $template['id'] : '';
                    
    				$selected = ( $wpsl_settings['template_id'] == $template_id ) ? ' selected="selected"' : '';
    				$dropdown .= "<option value='" . esc_attr( $template_id ) . "' $selected>" . esc_html( $template['name'] ) . "</option>";
                }
    			
    			$dropdown .= '</select>';
    			
    			return $dropdown;            
            }

    https://wpstorelocator.co/document/load-custom-store-locator-template/

    Any thoughts based on that?

    • This reply was modified 4 years, 10 months ago by shoxt3r.
    • This reply was modified 4 years, 10 months ago by shoxt3r.
    Thread Starter shoxt3r

    (@shoxt3r)

    Ah ok – I just tried disabling the plugin and the “theatre” page now uses the correct template of “archive-theatre.php” but it also reverts the “Store Locator” menu option within the Admin area back to “Theatres” which matches the settings I posted earlier.

    As soon as I activate the plugin again, it changes the menu option in the admin to “Store Locator” and reverts back to using the “index.php” page for the template.

    I suspect therefore there is a conflict or something I’ve missed when changing the “stores” references to “theatres” – any thoughts please?

    My only option may be to start again with the plugin and keep it as “stores” for now and see how I get on.

    Thread Starter shoxt3r

    (@shoxt3r)

    Ah ok – I just tried disabling the plugin and the “theatre” page now uses the correct template of “archive-theatre.php” but it also reverts the “Store Locator” menu option within the Admin area back to “Theatres” which matches the settings I posted earlier.

    As soon as I activate the plugin again, it changes the menu option in the admin to “Store Locator” and reverts back to using the “index.php” page for the template.

    I suspect therefore there is a conflict or something I’ve missed when changing the “stores” references to “theatres” – any thoughts please? My only option may be to start again with the plugin and keep it as “stores” for now and see how I get on.

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok no worries, thanks for the suggestions!

    When creating an “All Stores” page to hold the search tool where would this be created – is the intention just to use a standard page and place the shortcode on there?

    If you have a guide in the documentation that would be really helpful but when searching I didn’t find one.

    Thanks again.

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok I’ve now attempted to create a Parent Page for the “Theatres” CPT using the following code which hasn’t worked, despite resetting the Permalinks from within the WP settings.

    function create_theatre_acf_pages()
    {
    	if (function_exists('acf_add_options_page')) {
    		acf_add_options_sub_page(array(
    			'page_title'      => 'Theatre Parent Page Settings',
    			'parent_slug'     => 'edit.php?post_type=theatre',
    			'capability' => 'manage_options'
    		));
    	}
    }
    add_action('init', 'create_theatre_acf_pages');

    I’ve also created the “Theatre” page within my WordPress setup Pages area and created the corresponding “page-theatre.php” and “archive-theatre.php” but nothing seems to be working, not even if I reset the Permalink settings each time.

    If I can just find out why it’s defaulting to using the “index.php” despite setting a new page up to match as above ,then I’m sure I’d be able to solve it. Is there a default naming convention that WP Store Locator uses for it’s main “All Stores” page? If so, where would I find that setting please?

    If any other details would be help to look into this please let me know as I’m running out of ideas now haha

    Thanks in advance.

    Thread Starter shoxt3r

    (@shoxt3r)

    If it helps, here is the setup I have for WP Store Locator https://pasteboard.co/Kf0hLTO.png

    Thread Starter shoxt3r

    (@shoxt3r)

    Ok, so I’ve tried out a few different things and then decided to edit the index.php file as that was the only one that seemed relevant given the content that was showing and lo and behold that’s the template it’s using. I can’t figure out why that is though unless it’s a default for WordPress?

    I’ve since renamed the CPT to “theatre” and updated all plugin code accordingly, just in case it was getting mixed up with my previous CPT of “cinema” and causing a conflict.

    Note that the “single” page template is working fine – therefore “single-theatre.php” is being used as expected. I’m not aware of anywhere in the code where I set the index file as the default page template, nor for the “theatre” CPT. There is a parameter set for the “theatre” CPT which sets up an archive (“has_archive”) – however, setting up a new page with the name “archive-theatre.php” doesn’t change the layout as needed – the “theatre” CPT just continues to use the index.php for layout.

    At every stage I’ve saved the permalinks to ensure any new changes go through as expected but unfortunately it’s still not working.

    Below is the code I have to set parameters for the “theatre” CPT.

        // Theatre Post Type
        register_post_type('theatre', array(
            'show_in_rest' => true,
            'supports' => array('title', 'excerpt'),
            //'rewrite' => array('slug' => 'theatres'),
            'has_archive' => true,
            'public' => true,
            'labels' => array(
                'name' => 'Theatres',
                'add_new_item' => "Add New Theatre",
                'edit_item' => "Edit Theatre",
                'all_items' => "View All Theatres",
                'singular_name' => 'Theatre'
            ),
            'menu_icon' => 'dashicons-location-alt'
        ));

    Let me know if any further details would help.

    Thanks!

Viewing 15 replies - 1 through 15 (of 20 total)