Nkululeko
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: how to hook into a page’s title?You’re absolutely right. The theme titles are done differently. this is the code they use to display the title.
} $alignment = get_post_meta($post_id, 'alignment', true); $title_style_h1 = array(); $title_style_subtitle = array(); $title_box_bg_color = get_post_meta( $post_id, 'title_box_bg_color', true ); $title_box_font_color = get_post_meta( $post_id, 'title_box_font_color', true ); $title_box_line_color = get_post_meta( $post_id, 'title_box_line_color', true ); $title_box_custom_bg_image = get_post_meta( $post_id, 'title_box_custom_bg_image', true ); $title_tag = (empty(get_post_meta( $post_id, 'title_tag', true ))) ? 'h2' : get_post_meta( $post_id, 'title_tag', true ); $sub_title = get_post_meta( $post_id, 'sub_title', true ); $breadcrumbs = get_post_meta( $post_id, 'breadcrumbs', true ); $breadcrumbs_font_color = get_post_meta( $post_id, 'breadcrumbs_font_color', true ); $title_box_subtitle_font_color = get_post_meta( $post_id, 'title_box_subtitle_font_color', true ); $sub_title_instead = get_post_meta($post_id, 'sub_title_instead', true); if( empty($alignment) || is_post_type_archive(stm_listings_post_type()) ) { $alignment = 'left'; }
I think this the actual code that displays the title.
$title_tag = (empty(get_post_meta( $post_id, 'title_tag', true ))) ? 'h2' : get_post_meta( $post_id, 'title_tag', true );
Is there a possibilty to hook into it?
Another solution I might be thinking of, is instead of trying to hook into the pages title, how about I echo (as an H1 title) the yoast meta-title (I’ve set using the same code with
wpseo_title
)I’ve tried it with this code
echo get_post_meta($post->ID, '_yoast_wpseo_title', true);
But I think the
_yoast_wpseo_title
key returns the title of post-type and not the custom title I’ve just madeI’ve also tried it with this code…
<h1 class="archive-title"> --------------> this is Line 3 <?php if ( is_tax() ) : $taxonomy = get_queried_object()->taxonomy; $term_id = get_queried_object()->term_id; $meta = get_option( 'wpseo_taxonomy_meta' ); $title = $meta[$taxonomy][$term_id]['wpseo_title']; //printf( '<pre>%s</pre>', print_r( get_option( 'wpseo_taxonomy_meta' ), 1 ) ); if ( isset($meta) && !empty($title) ) : echo apply_filters( 'the_title', $title ); else : single_term_title(); endif; endif; ?> </h1>
This keeps returning a
Parse error: syntax error, unexpected '<', expecting end of file in .......................stm_classic_filter.php on line 3
no matter what I doWhat would you suggest?
Alright. Thanks again for helping me out with this. Couldn’t have done it without your help. Much appreciated.
Alright, I get what you’re saying. So what happens when the hide_empty is true, and lets say we have 10 car posts on this link …/location/new-york/model/bmw right, and all 10 car posts on this link expire in 30 days, so obviously the link will be removed from the sitemap because its empty right, will the link also be removed from Google and then indexed again when the link gets posts?
Yeah, that would create complications. makes sense. Lets rather leave the tax bases as is then. a link with tax bases and a link without, would get the same ranking on search engines, there isn’t much of a difference right?
WOOOWW!! IT WORKED!!! You’re a genius! Your knowledge of PHP is insane! I honestly almost gave up on it. I see you also managed to figure out the DB query. I stumbled upon a few glitches in the beginning, but I knew from the get-go that it was caused by one of the plugins I installed, soon as I found which one it was and de-activated it, your plugin worked like a charm.
What I did was, when I set the hide_empty to false and then I set the Max. Items on 2000 and your plugin split it into 40 sitemap pages as you said it should. This way it outputs 2048 links per sitemap page, so we know for sure that it can handle all the links. This works perfectly fine for me. anything from 8000 Max. Items causes that timeout notice. But overall I’m happy with everything. I still can’t believe you figured it out. I can’t thank you enough. You’re the man!
Now that we done with the sitemap issue( I still can’t believe we done), It now brings us to that canonical links issue that you brought up. I know what a canonical link is, but I seem not to entirely understand why we need it on these links. Do we still need it even when the hide_empty is true? If the links have no related posts and we place a canonical link on them, does that mean they won’t get indexed by Mr. Google?
Here’s another puzzle challenge you might find interesting, I tried it. I got stuck, and then I gave up on it(because I was told it is not possible on wordpress), just a quick one. Is it possible to remove taxonomy bases from double term links e.g
example.com/used-cars/location/los-angeles/model/audi
toexample.com/used-cars/los-angeles/audi
. If you say yes, I’ll start it as a new topic and post the code where I got stuck and you can tell me what I’m doing wrong. and also, would it make a difference, in terms of page ranking if I removed the taxonomy bases?Hahaha.. Well, good things require time!
Of course. I’d like to see how you split the links with code. I never thought that’s possible.
Alright! Thats great, so we good with memory.
I’ll go for VPS then. Currently the site is on localhost, I usually work on sites while on localhost, and then only upload them when everything is good. I’ve had bad experiences editing live sites.
Alright, not a problem! Oh thanks to you. I would have never been able to figure this out on my own. If you don’t mind me asking, what kind of projects do you usually work on?
Alright, I may have found a solution. I managed to change those URLs( /model/audi/ ) into these /used-cars/model/audi for the entire site, so right now thats how they generate into the sitemap. So we can exclude single term links. that’s sorted.
The reason why I actually needed the the hide_empty to be set on false is mainly because I wanted to be certain that it’s possible to get all 90k links into a sitemap. Because I eventually wanted to export about 30k car posts from the previous site, into the the one that we currently working on. I can’t tell if these 30k car posts are assigned to all the terms, but I’m sure it will get to that point in the near future. The google bot issue makes perfect sense, I didn’t think of that. Somebody did actually mention canonicals, I just didn’t take it seriously, Cause I couldn’t fully understand what he meant. However we will revisit this issue, I need more clarity on it, For now lets focus on the get_terms() issue, it’s giving me alot of sleepless nights.
Right! I haven’t done any optimization of the DB ever for this site. I’ve installed and removed alot of plugins. not to mention post revisions. They could’ve caused alot of bloat. I’ll do a 360 optimization of the DB and see if that changes anything. I was planning on a VPS hosting plan for this site, could that help?
Yeah You’re right. Increasing the execution time won’t help when the links get crawled.
Hmm.. How do we cache the term arrays? I think we should also try that. Lets rather fail knowing we tried every possibility.
Alright, Lets try everything we can think of. take your time.
Yeah, you got it! the alt_get_terms functions works. But Hold up, are you saying the timeout problem can be solved if we generate/split links into their own multiple sitemap files? Cause remember our ultimate goal is to get links with hide_empty => false
Max number of terms are as follows:
648 terms currently max 700 terms for vehicle model
128 terms currently max 500 terms for vehicle locationI’m not sure if its possible to configure yoast to generate single term links? I could be wrong, but it seems like Yoasts entire sitemap feature generates only pages, posts and URLs assigned to posts for taxonomies, and also… I would’ve liked to have that /used-cars/ also added in the single term URLs. Yoast can only generate these URLs https://www.example.com/model/audi, these are viewed via taxonomy.php, and actually not through the custom post type, which is really not ideal.
Alright, so the test code did return some URLs like you said it should, however the URLs it returned are those with posts assigned to them, meaning it only returned URLs when
hide_empty
was set to true right.Then when the
hide empty
was set to false, we get almost the same problem as BWP-GS, but this time around it states the error. this is what I got…( ! ) Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\autocity\wp-includes\class-wp-hook.php on line 284 Call Stack # Time Memory Function Location 1 0.0040 367680 {main}( ) ..\index.php:0 2 0.0060 371304 require( 'C:\wamp\www\autocity\wp-blog-header.php' ) ..\index.php:17 3 5.5573 65620184 wp( ) ..\wp-blog-header.php:16 4 5.5573 65620296 WP->main( ) ..\functions.php:955 5 5.5710 65717544 WP->query_posts( ) ..\class-wp.php:735 6 5.5711 65717632 WP_Query->query( ) ..\class-wp.php:617 7 5.5711 65718496 WP_Query->get_posts( ) ..\class-wp-query.php:3238 8 5.5722 65726496 do_action_ref_array( ) ..\class-wp-query.php:1681 9 5.5722 65726640 WP_Hook->do_action( ) ..\plugin.php:515 10 5.5722 65726720 WP_Hook->apply_filters( ) ..\class-wp-hook.php:323 11 5.5722 65727496 call_user_func_array ( ) ..\class-wp-hook.php:298 12 5.5722 65727680 WPSEO_Sitemaps->redirect( ) ..\class-wp-hook.php:0 13 5.5723 65727728 WPSEO_Sitemaps->get_sitemap_from_cache( ) ..\class-sitemaps.php:206 14 5.5809 65783496 WPSEO_Sitemaps->refresh_sitemap_cache( ) ..\class-sitemaps.php:248 15 5.5809 65783528 WPSEO_Sitemaps->build_sitemap( ) ..\class-sitemaps.php:270 16 5.5809 65783528 WPSEO_Sitemaps->build_root_map( ) ..\class-sitemaps.php:292 17 6.6518 66008248 WPSEO_Sitemaps_Renderer->get_index( ) ..\class-sitemaps.php:345 18 6.6529 66009616 apply_filters( ) ..\class-sitemaps-renderer.php:66 19 6.6529 66009880 WP_Hook->apply_filters( ) ..\plugin.php:203 20 6.6530 66010744 call_user_func_array ( ) ..\class-wp-hook.php:298 21 6.6530 66010928 add_sitemap_custom_items( ) ..\class-wp-hook.php:0 22 30.0374 78464384 home_url( ) ..\functions.php:190 23 30.0374 78464448 get_home_url( ) ..\link-template.php:2969 24 30.0374 78464496 get_option( ) ..\link-template.php:2995 25 30.0376 78464768 apply_filters( ) ..\option.php:141 26 30.0377 78465152 WP_Hook->apply_filters( ) ..\plugin.php:203
( ! ) Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\autocity\wp-includes\wp-db.php on line 668 Call Stack # Time Memory Function Location 1 0.0040 367680 {main}( ) ..\index.php:0 2 0.0060 371304 require( 'C:\wamp\www\autocity\wp-blog-header.php' ) ..\index.php:17 3 5.5573 65620184 wp( ) ..\wp-blog-header.php:16 4 5.5573 65620296 WP->main( ) ..\functions.php:955 5 5.5710 65717544 WP->query_posts( ) ..\class-wp.php:735 6 5.5711 65717632 WP_Query->query( ) ..\class-wp.php:617 7 5.5711 65718496 WP_Query->get_posts( ) ..\class-wp-query.php:3238 8 5.5722 65726496 do_action_ref_array( ) ..\class-wp-query.php:1681 9 5.5722 65726640 WP_Hook->do_action( ) ..\plugin.php:515 10 5.5722 65726720 WP_Hook->apply_filters( ) ..\class-wp-hook.php:323 11 5.5722 65727496 call_user_func_array ( ) ..\class-wp-hook.php:298 12 5.5722 65727680 WPSEO_Sitemaps->redirect( ) ..\class-wp-hook.php:0 13 5.5723 65727728 WPSEO_Sitemaps->get_sitemap_from_cache( ) ..\class-sitemaps.php:206 14 5.5809 65783496 WPSEO_Sitemaps->refresh_sitemap_cache( ) ..\class-sitemaps.php:248 15 5.5809 65783528 WPSEO_Sitemaps->build_sitemap( ) ..\class-sitemaps.php:270 16 5.5809 65783528 WPSEO_Sitemaps->build_root_map( ) ..\class-sitemaps.php:292 17 6.6518 66008248 WPSEO_Sitemaps_Renderer->get_index( ) ..\class-sitemaps.php:345 18 6.6529 66009616 apply_filters( ) ..\class-sitemaps-renderer.php:66 19 6.6529 66009880 WP_Hook->apply_filters( ) ..\plugin.php:203 20 6.6530 66010744 call_user_func_array ( ) ..\class-wp-hook.php:298 21 6.6530 66010928 add_sitemap_custom_items( ) ..\class-wp-hook.php:0 22 30.0374 78464384 home_url( ) ..\functions.php:190 23 30.0374 78464448 get_home_url( ) ..\link-template.php:2969 24 30.0374 78464496 get_option( ) ..\link-template.php:2995 25 30.0376 78464768 apply_filters( ) ..\option.php:141 26 30.0377 78465152 WP_Hook->apply_filters( ) ..\plugin.php:203 27 30.0409 78461448 wpdb->__destruct( ) ..\wp-db.php:0
Forum: Fixing WordPress
In reply to: get terms() alternativeHi Michael,
Basically I want to loop through these type of URLs
www.example.com/used-cars/location/new-york/model/bmw
&www.example.com/used-cars/model/mercedes-benz
and push them into a sitemap.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 ) { $pages[] = array( 'location' => home_url( '/used-cars/model/' . $model->slug ), 'lastmod' => '27/04/2017', 'frequency' => 'auto', 'priority' => '0.8' ); foreach ( $locations as $location ) { $pages[] = array( 'location' => home_url( '/used-cars/location/' . $location->slug . '/model/' . $model->slug ), 'lastmod' => '27/04/2017', 'frequency' => 'auto', 'priority' => '0.8' ); } } return $pages; }
So a problem I encounter with this code is that, when I set the
hide_empty
to true, I get only URLs with posts assigned to them, but then when I set it to false as it is in the code, I get a WSOD.So my guess is that, the problem lies with
get_terms
Thats exactly what I was trying to avoid in the first place, having extra plugins that do the same thing. I already use Yoast for the sites SEO. Lets stick with Yoast then.
So its possible to split the links into different sitemap pages, without the feature being offered in the plugin? Alright, Lets give it a shot and see if it pans out.
Ah! of course, the get terms, our main problem. Please let me know if you’ve managed with the SQL solution. Can’t we also try it with that
alt_get_terms
solution you provided earlier? could that work this time around?Ahhhh! I get it. Thats what I was asking about on this previous question ,about the function being used to add a sitemap.xml rather than URLs . but then again I thought URLs were going to show up in the root(sitemapindex) anyway and then as the next step, I was going to ask you how we could push the URLs into a -sitemap.xml folder.
Yeah you are right, google will reject them, and the actual reason for all this, is to get these URLs indexed on search engines.
hmm! So Yoast doesn’t break the content into multiple sitemap files. That’s going to be problematic because we have about 82.9k permutations if I’m not mistaken, with
vehicle_model
having 648 terms andvehicle_location
having 128 terms. this is a feature that the BWP-GS plugin got really well.The vehicle location single term URL was left out intentionally, but now when I think about it, it would actually make sense to have it in there, so yeah lets include it in the function.
Yoast does generally generate single taxonomy links, but the new york location link would look like this example.com/location/new-york/. tell me, do you think google would see these links(example.com/location/new-york & example.com/used-cars/location/new-york) as duplicate content and then penalize my site? because these two links provide the same content in the site.
Thats another question I was going to ask at a later stage, I don’t think Yoast has the option or a function to flush the cache, this is another feature that BWP-GS got right.
Geesh! In your opinion, do you think Yoast can handle 82.9k links? given your experience, what would you do to solve this issue? I’m all out of ideas. It doesn’t matter what plugin we use at this stage, Whats important is… can it get the job done.
Alright not a problem, take as much time as you need. On my side, I’ll keep checking the themes code to see if I can spot anything, I can also copy & paste the themes code from any section that you think the issue might be, to see if we could find anything
Geesh! I wonder why it isn’t working on my site. Alright I’ll add that last trailing slash.
I’m 100% sure of the taxonomy names. here is what it shows for location
https://localhost/autocity/wp-admin/edit-tags.php?taxonomy=vehicle_location&post_type=used-cars
and this for modelshttps://localhost/autocity/wp-admin/edit-tags.php?taxonomy=vehicle_model&post_type=used-cars
I once heard someone mention getting terms through SQL, But I have zero knowledge of how to work it.
Yeah, they are hierachical, Sorry about that, I should have mentioned. like for example on models there is…
Audi audi -Audi A4 audi-a4 -Audi A6 audi-a6 etc
… and then on locations there’s…
South Africa south-africa -Western Cape western-cape --Cape Town cape-town etc
Could this change things?
Ah I get what you mean, lets stick to your solution and see where it takes us.
I’ll make sure I update my PHP. Would I still need to change it back to
[{array_items}]
after I updated it?So the error is fixed, but now the code seems to not have any effect, there is no changes in the sitemapindex, please double check the code again for me to see if everything is it should be.
function alt_get_terms( $tax ) { $hide_empty = true; $term_query = new WP_Term_Query( array('taxonomy'=> $tax, 'hide_empty'=> $hide_empty,)); return $term_query->get_terms(); } 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, ) ); */ remove_all_filters('get_terms_args'); remove_all_filters('terms_clauses'); $models = alt_get_terms('vehicle_model'); $locations = alt_get_terms('vehicle_location'); // Loop through the search terms $pages = ''; foreach ( $models as $model ) { $location2 = home_url( '/used-cars/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"; 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; }