Answer the question
In order to leave comments, you need to log in
If there is, then show me - in Wordpress, is it harmful?
Good evening!
Please tell me, I use the "If there is, then show" condition on the WordPress pages to display additional fields specified in the post. I.e:
<?php if ( get_post_meta($post->ID, 'имя-поля', true) ) : ?>
Ляля <?php echo get_post_meta($post->ID, 'имя-поля', true) ?> - <?php the_title(); ?> лялял <?php the_title();>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
Thanks everyone for the replies.
I solved the problem by changing the hoster + slightly improved the hardware.
Now: VDS - 8 GB RAM, 6 CPU cores
Problems are gone!
PS: The last straw was the inaccessibility of the site for 7 hours due to a complete server crash (not only the database, as it was before)
Do you have Memcached / Redis on the server? In general, when you receive a post/posts, by default WP requests and caches their metadata. So all calls to get_post_meta() inside the Loop do not give any load on the database, these requests go exclusively to the cache (runtime or persistent). So you can safely use such code and not worry about it.
As for MySQL itself - keep it running for at least a week (optimally - a month) in order to accumulate statistics. Analyze - via MySQL Tuner, PHPMyAdmin, via SQLProfiler, mysqlslap, see slow query log, look for memory leaks or sticky queries.
if ( $var = get_post_meta($post->ID, 'имя-поля', true) )
this will not give a large load, as mentioned above, requests are cached.
but, if you are very worried, you can collect all custom fields once with one request into one variable
and continue to use it in your code on this page like this
<?php if ( isset($custom['имя-поля']) && !empty($custom['имя-поля'][0])) : ?>
Ляля <?php echo $custom['имя-поля'][0]; ?> - <?php the_title(); ?> лялял <?php the_title();>
<?php endif; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question