Forum Replies Created

Viewing 15 replies - 16 through 30 (of 43 total)
  • Thread Starter Nkululeko

    (@oieniuz)

    Alright, I see where you going with it.

    I did as you said, but then there seems to be an error on this line of the function

    $term_query = new WP_Term_Query(['taxonomy'=> $tax, 'hide_empty'=> $hide_empty,]);

    This is what I got

    Parse error: syntax error, unexpected '[', expecting ')' in C:\wamp\www\autocity\wp-content\themes\autocity\functions.php on line 165

    I tried to remove the ‘[‘ but it lead me to even more errors.

    and also I been meaning to ask you, a friend sugested that we try ‘get_queried_object’ function as a parameter in ‘get_the_terms’

    e.g obj= get_queried_object()
        $models= get_the_terms( $obj, 'vehicle_model')

    Could something like this work?

    Thread Starter Nkululeko

    (@oieniuz)

    Right, I got it

    Yeah, I meant the $location and $model part, I believe everything else is the way it should be.

    So I tried the code, and it did not return anything when I generated the sitemap. Please double check the final code, maybe you might pickup on a glitch somewhere

     add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
    function add_sitemap_custom_items(){
    
        $models = get_terms( array(
            'taxonomy' => 'vehicle_model',
            'hide_empty' => true,
        ) );
        $locations = get_terms( array(
            'taxonomy' => 'vehicle_location',
            'hide_empty' => true,
        ) );
    
        // Loop through the search terms
        $pages = '';
        foreach ( $models as $model ) {
            $location2 = home_url( '/used-cars/model/' . $models->slug );
            $pages .= "<sitemap><loc>$location2</loc><lastmod>2017-04-04T23:59:00+00:00</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></sitemap>\n";
            foreach ( $locations as $location ) {
                $location2 = home_url( '/used-cars/location/' . $location->slug . '/model/' . $model->slug );
                $pages .= "<sitemap><loc>$location2</loc><lastmod>2017-04-04T23:59:00+00:00</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></sitemap>\n";
            }  
       }
       return $pages;
    }
    Thread Starter Nkululeko

    (@oieniuz)

    Oh I see, it makes sense now.

    Ah yes, I hope it works out, It was my ideal choice anyway. I think it does break entries up, there is a section where you can set a limit for entries in a sitemap, So I think that won’t be an issue.

    So I tried the code as you said, I could be doing something wrong, it returned an error, this is what it showed

    Parse error: syntax error, unexpected $end in C:\wamp\www\autocity\wp-content\themes\autocity\functions.php on line 185

    
    add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
    function add_sitemap_custom_items(){
    {
        $models = get_terms( array(
            'taxonomy' => 'vehicle_model',
            'hide_empty' => true,
        ) );
        $locations = get_terms( array(
            'taxonomy' => 'vehicle_location',
            'hide_empty' => true,
        ) );
    
        // Loop through the search terms
        $pages = '';
        foreach ( $models as $model ) {
            $location2 = home_url( '/used-cars/model/' . $models->slug );
            $pages .= "<sitemap><loc>$location2</loc><lastmod>2017-04-04T23:59:00+00:00</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></sitemap>\n";
            foreach ( $locations as $location ) {
                $location2 = home_url( '/used-cars/location/' . $location->slug . '/model/' . $model->slug );
                $pages .= "<sitemap><loc>$location2</loc><lastmod>2017-04-04T23:59:00+00:00</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></sitemap>\n";
            }  
       }
       return $pages;     <----- this is line 185

    I’ve shown line 185 in the code, also I see on the line after the foreach() statements you wrote the variables as singular

    e.g $location2 = home_url( '/used-cars/location/' . $location->slug . '/model/' . $model->slug );

    Is this is a typo, or thats how it should be?

    Thread Starter Nkululeko

    (@oieniuz)

    One more thing, There is another error I might have missed that showed up after I turned on WP_DEBUG, I think this could be causing the glitch.

    “Warning: include(C:\wamp\www\autocity/wp-content/advanced-cache.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\autocity\wp-settings.php on line 84”

    Call Stack
    #	Time	Memory	Function	Location
    1	0.0034	368568	{main}( )	..\index.php:0
    2	0.0173	372192	require( 'C:\wamp\www\autocity\wp-blog-header.php' )	..\index.php:17
    3	0.0189	397648	require_once( 'C:\wamp\www\autocity\wp-load.php' )	..\wp-blog-header.php:13
    4	0.0208	411816	require_once( 'C:\wamp\www\autocity\wp-config.php' )	..\wp-load.php:37
    5	0.0234	580448	require_once( 'C:\wamp\www\autocity\wp-settings.php' )	..\wp-config.php:92

    and then there is…

    “Warning: include() [function.include]: Failed opening ‘C:\wamp\www\autocity/wp-content/advanced-cache.php’ for inclusion (include_path=’.;C:\php\pear’) in C:\wamp\www\autocity\wp-settings.php on line 84”

    Call Stack
    #	Time	Memory	Function	Location
    1	0.0034	368568	{main}( )	..\index.php:0
    2	0.0173	372192	require( 'C:\wamp\www\autocity\wp-blog-header.php' )	..\index.php:17
    3	0.0189	397648	require_once( 'C:\wamp\www\autocity\wp-load.php' )	..\wp-blog-header.php:13
    4	0.0208	411816	require_once( 'C:\wamp\www\autocity\wp-config.php' )	..\wp-load.php:37
    5	0.0234	580448	require_once( 'C:\wamp\www\autocity\wp-settings.php' )	..\wp-config.php:92

    The problem is, I have no idea what this is.

    Thread Starter Nkululeko

    (@oieniuz)

    I see. the reason why I thought the problem could be the plugin itself, was after reading the plugins FAQ page

    I’ve once modified my custom post type title to get taxonomy term names from the term_ID before on this very same website I’m working on, and it functions perfectly. This is the code I used right

    add_filter(‘wpseo_title’, ‘vehicle_listing_title’);

    function vehicle_listing_title( $title ) 
    {
      if ( is_post_type_archive('used-cars') && $id = get_queried_object_id() ) 
      {
       
         
        $locations = get_query_var('location');
        $location = get_term_by('slug', $locations, 'vehicle_location');
        $models = get_query_var('model');
        $model = get_term_by('slug', $models, 'vehicle_model'); 
        
        $title = '';
    
        if($model && $model) $title .= $model->name . ' used';
        else $title .= 'Used';
    
        $title .= ' cars for sale';
    
        if($location && $location) $title .= ' in ' . $location->name;
    
        $title .= ' on ' . get_bloginfo('name');
    
        return $title;
      }
    
      return $title;
    }

    Basically this code gets the term name from the same object that we trying to get the slug from, and it works perfectly fine. Do you still think the problem could still be from the theme?

    The one thing I haven’t tried is “To narrow down the conflict source, temporarily copy your get_terms() calls to near the bottom of your theme’s page.php template. Add code to var_dump the assigned variables.” I’ll get on it right now

    Its really confusing. I don’t know if this is going to change anything, but I’m considering trying using yoast to generate this sitemap, of which was initially my first choice. I’m just not sure of this code, please check this example out

    function add_sitemap_custom_items(){
    $sitemap_custom_items = '<sitemap>
    <loc>https://www.website.com/custom-page-1/</loc>
    <lastmod>2012-12-18T23:12:27+00:00</lastmod>
    </sitemap>
    <sitemap>
    <loc>https://www.website.com/custom-page-2/</loc>
    <lastmod>2012-12-18T23:12:27+00:00</lastmod>
    </sitemap>
    <sitemap>
    <loc>https://www.website.com/custom-page-3/</loc>
    <lastmod>2012-12-18T23:12:27+00:00</lastmod>
    </sitemap>';
    return $sitemap_custom_items;
    }
    add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );

    Do you think I could use this function to achieve what I’m trying to do? It seems like its used to add an external sitemap rather than external pages, I’m not sure, what do you think?

    Thread Starter Nkululeko

    (@oieniuz)

    Oh I see, I had no idea it could be a PHP error, I thought it had something to do with memory or cache features in the plugin. So I did set WP_DEBUG to true, and it showed a couple of theme errors due to updating my WP right, they were mostly widgets related, so I managed to fix those. Then when I went on to generate the sitemap, my browser says the site can’t be reached, like “The webpage at https://localhost/autocity/page_external.xml?generate=1&t=1491918248 might be temporarily down or it may have moved permanently to a new web address.”

    When I set WP_DEBUG back to False, it shows the WSOD once again. However when I set hide_empty to true on get_terms the terms show in the sitemap, but only terms from vehicle posts.

    Could this still be from a glitch in the code?

    • This reply was modified 7 years, 11 months ago by Nkululeko.
    • This reply was modified 7 years, 11 months ago by Nkululeko.
    Thread Starter Nkululeko

    (@oieniuz)

    Alright, I did everything as you said. I think the issue was that I was using an older version of WP, as I was developing on localhost. I’m not sure if its functioning properly right now, but it seems like it is, because when I generate the sitemap it shows a blank white screen, of which I’m guessing its caused by the large number of entries as you mentioned earlier. the plugin has an option to split entries by 50 000 links, but it returns a white screen regardless.

    I’ll probably take this up with the plugin author. Thanks for your help and patience. much appreciated

    Thread Starter Nkululeko

    (@oieniuz)

    Of course, I’ll try be more descriptive. Firstly here is the exact code I’m using, I noticed the one on my previous comment is incomplete.

    add_filter( 'bwp_gxs_external_pages', 'bwp_gxs_external_pages', 10, 1 );
    function bwp_gxs_external_pages($pages)
    {
        $models = get_terms( array(
            'taxonomy' => 'vehicle_model',
            'hide_empty' => false,
        ) );
        $locations = get_terms( array(
            'taxonomy' => 'vehicle_location',
            'hide_empty' => false,
        ) );	
    
        // Loop through the search terms
        foreach ( $models as $model ) {
            foreach ( $locations as $location ) {
                $pages[] = array(
                    'location' => home_url( '/used-cars/location/' . $location->slug . '/model/' . $model->slug ),
                    'lastmod' => '04/04/2017',
                    'frequency' => 'auto', 
                    'priority' => '0.8'
                );
            }  
            $pages[] = array(
                'location' => home_url( '/used-cars/model/' . $models->slug ),
                'lastmod' => '04/04/2017',
                'frequency' => 'auto', 
                'priority' => '0.8'
            );   
        }
    
       return $pages;
    }

    and this is what I’m getting when I generate the sitemap

    https://mysite.com/used-cars/location//model/	0.8		2017-04-04 00:00
    https://mysite.com/used-cars/location//model/	0.8		2017-04-04 00:00
    https://mysite.com/used-cars/model/	        0.8		2017-04-04 00:00
    https://mysite.com/used-cars/location//model/	0.8		2017-04-04 00:00
    https://mysite.com/used-cars/location//model/	0.8		2017-04-04 00:00
    https://mysite.com/autocity/used-cars/model/

    I think you’re right about get_terms() being the reason terms aren’t showing. I’ve tried setting the hide_empty to true as you suggested, and it returned the same results as above.

    • This reply was modified 7 years, 11 months ago by Nkululeko.
    Thread Starter Nkululeko

    (@oieniuz)

    Don’t mind my last reply. Your solution worked perfectly. Thanks alot man.

    Thread Starter Nkululeko

    (@oieniuz)

    The issue is… my Custom post type does not have the title displayed. I don’t think get_the_archive_title will hook when there is no title. I basically want to echo the vehicle_listing_title as an H1 heading, or create one to match

    • This reply was modified 7 years, 11 months ago by Nkululeko.
    Thread Starter Nkululeko

    (@oieniuz)

    Alright, Now I get it. Your code fetches posts in the used-cars custom post type, but the plugin already handles that. what I want to generate into a sitemap are actual search queries from a search form. meaning, these www.example.com/used-cars/location/new-york/model/bmw & www.example.com/used-cars/model/mercedes-benz are search URLs and not post URLs. By “thousands of them” I meant search URLs for all the location and model terms.

    In terms of the sitemap entry limit, the plugin also handles that. It automatically splits them into 50 000 per entry, which is why I picked to use this particular plugin

    This is what I’ve tried recently. This code should give you a better understanding of what I’m trying to achieve

    add_filter( 'bwp_gxs_external_pages', 'bwp_gxs_external_pages', 10, 1 );
    function bwp_gxs_external_pages($pages)
    {
        $models = get_terms( array(
            'taxonomy' => 'vehicle_model',
            'hide_empty' => false,
        ) );
        $locations = get_terms( array(
            'taxonomy' => 'vehicle_location',
            'hide_empty' => false,
        ) );
    
        // Loop through the search terms
        foreach ( $models as $model ) {
            foreach ( $locations as $location ) {
                $pages[] = array(
                    'location' => home_url( '/used-cars/location/' . $location->slug . '/model/' . $model ),
                    'lastmod' => '04/04/2017',
                    'frequency' => 'auto', 
                    'priority' => '0.8'
                );
            }  
            $pages[] = array(
                'location' => home_url( '/used-cars/model/' . $model ),
                'lastmod' => '04/04/2017',
                'frequency' => 'auto', 
                'priority' => '0.8'
            );   
        }
    
       return $pages;
    }

    But this too didn’t work.

    Thread Starter Nkululeko

    (@oieniuz)

    Okay, When I hardcode the sitemap entry, it does show up. So I then proceeded to query the pages to add like you said, but it kept returning a parse error. I tried making changes here and there but still no luck. Please check it out for me and tell me what am I doing wrong

    add_filter( 'bwp_gxs_external_pages', 'bwp_gxs_external_pages', 10, 1 );
    function bwp_gxs_external_pages($pages)
    {
    
    // The Query
    $the_query = new WP_Query( $args );
     
    // The Loop
    if ( $the_query->have_posts() ) {
        
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
    
      $locations = get_terms( array(
              'taxonomy' => 'vehicle_location',
              'hide_empty' => false,
        ) );
       $models = get_terms( array(
            'taxonomy' => 'vehicle_model',
            'hide_empty' => false,
        ) );
    
    // Defining $args
    $args = array(
        'post_type' => 'used-cars',
        'tax_query' => array(
            array(
                'taxonomy' => 'vehicle_location',
                'field'    => 'slug',
                'terms'    => $locations,
                'relation' => 'IN',
            ),
            array(
                'taxonomy' => 'vehicle_model',
                'field'    => 'slug',
                'terms'    => $models,
                'relation' => 'IN',
            ),
        ),
    );
    $query = new WP_Query( $args );
    
              global $post;
         $data = array(
       'location'  => get_permalink(),
       'lastmod'   => $post->post_modified,
       'frequency' => 'auto',
       'priority'  => '0.8',
    );
    $pages[] = $data;
    
        }
    
       return $pages;
    }
    Thread Starter Nkululeko

    (@oieniuz)

    Oh no, The links still aren’t showing in the sitemap. The code should still be in an add_filter() right? and should be placed in functions.php

    like this

    // add to theme's functions.php
    add_filter('bwp_gxs_external_pages', 'bwp_gxs_external_pages');
    function bwp_gxs_external_pages($pages)
    {
    
    $data = array(
       'location'  => get_permalink(),
       'lastmod'   => $post->post_modified,
       'frequency' => 'auto',
       'priority'  => '0.8',
    );
    $pages[] = $data;
    }
    Thread Starter Nkululeko

    (@oieniuz)

    Alright, I get what you’re saying. I wouldn’t have figured this out by myself. Thanks for the help.

    Thread Starter Nkululeko

    (@oieniuz)

    Right, I got you.

    just need a bit more clarity on 'location' => get_permalink(),. how would the get_permalink() function know which permalinks to get?

    • This reply was modified 7 years, 12 months ago by Nkululeko.
Viewing 15 replies - 16 through 30 (of 43 total)