Here, I wrote a function that side-steps the ACF library and just grabs them from the database, just use it using post_type
You can get post_type from ID with get_post_type( $ID )
function get_acf_fields_post_type( $post_type )
{
global $wpdb;
$sql = "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as rule
FROM $wpdb->posts p
LEFT JOIN $wpdb->postmeta pm
ON ( p.ID = pm.post_id AND pm.meta_key = 'rule' )
WHERE p.post_type = 'acf'";
$result = $wpdb->get_results($sql);
$groups = array();
foreach($result as $row){
$rule = unserialize($row->rule);
if( $rule['param'] == 'post_type' && $rule['operator'] == '==' && $rule['value'] == $post_type )
{
$groups[$row->ID] = array('title'=>$row->post_title,'name'=>$row->post_name);
}
}
foreach($groups as $post_id => $data)
{
$fsql = "SELECT * FROM $wpdb->postmeta WHERE post_id = '$post_id' AND meta_key LIKE 'field_%';";
$fields = $wpdb->get_results($fsql);
$field_array = array();
foreach($fields as $field)
{
$f = unserialize($field->meta_value);
$field_array[$field->meta_key] = $f;
}
$groups[$post_id]['fields'] = $field_array;
}
return $groups;
}
Thanks a lot, I’ve already did it this way, and it works
<div class="row">
<?php if(have_rows('table_forms')): ?>
<?php $numrows = count( get_field( 'table_forms' ) ); ?>
<?php while ( have_rows('table_forms') ) : the_row(); ?>
<?php if($numrows <3) {$counttables = 6;} else {$counttables = 4;} ?>
<div class="col-md-<?php echo $counttables; ?>">
<div class="main-table">
<h3><?php the_sub_field('table_forms_name'); ?></h3>
<table class="table main-table-slyle">
<tbody>
<tr>
<td class="main-table-td"><h3>Длительность</h3></td>
<td><?php the_sub_field('table_forms_dlit'); ?></td>
</tr>
<tr>
<td class="main-table-td"><h3>Количество часов</h3></td>
<td><?php the_sub_field('table_forms_kol'); ?></td>
</tr>
<tr>
<td class="main-table-td"><h3>Уровень</h3></td>
<td>
<?php the_sub_field('table_forms_urov'); ?>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<?php endwhile;?>
<?php
else :
// no rows found
endif;
?>
</div>
OK my bad, I was forgetting my namespacing!!!
Should have been:
add_filter('acf/upload_prefilter/name=unique_upload_image', '\App\my_acf_upload_prefilter');
However, although this now works, it’s still not displaying the error message I defined, it’s just saying ‘HTTP error’?
Any ideas?
Kev
does this help: https://support.advancedcustomfields.com/forums/topic/order-by-subfield-values/
seems like you can do subnested orderbys now: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
(i didn’t know about this until now – very exciting!)
Phil
for now I have this:
<?php
$args = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘eventos’,
‘status’ => ‘programa’,
‘orderby’ => array(
‘title’ => ‘ASC’)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<hr>
<?php the_field(‘evento-viagem’); ?> / <?php the_field(‘evento-audiencia’); ?><br>
“><?php the_title(); ?><br>
<?php if( get_field(‘evento-subtitulo’) ): ?>
<?php the_field(‘evento-subtitulo’); ?><br>
<?php endif; ?>
<?php the_field(‘evento-caminho’); ?> <?php the_field(‘evento-ano’); ?><br>
<?php if( have_rows(‘evento-paragens’) ): ?>
<?php
$posts = get_sub_field(‘evento-local’);
if( $posts ): ?>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<?php echo get_the_title( $p->ID ); ?> <?php the_field(‘local-cidade’, $p->ID); ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
wich Outputs something like this:
DAY 1 — HOUR — EVENT A — CITY
DAY 1 — HOUR — EVENT A — CITY
DAY 2 — HOUR — EVENT A — CITY
DAY 2 — HOUR — EVENT A — CITY
DAY 1 — HOUR — EVENT B — CITY
DAY 1 — HOUR — EVENT B — CITY
DAY 2 — HOUR — EVENT B — CITY
DAY 2 — HOUR — EVENT B — CITY
Hi @dotcircle
I would add some hot JS action onto the link. When the user clicks that link, you could use wp AJAX api (https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)) to fire off an email to your client.
This isn’t really an ACF specific question – so if you have any further questions, I would try asking it on a WordPress forum. You may get better/faster help!
Phil
@macreixa what does your WP_Query
look like?
Hi @arctica112
I’m not fully understanding what you’re after – and this forum is really for this sort of topic (this is more of a general PHP question) BUT I think you just need to do something like this:
$amount = count(get_sub_field('table_forms')
this will give you the total number of items in your repeater. Then you can check that number to determine how many columns you’ll be needing.
Phil
Thank you for your answer. I’ve reviewed the Code of ACF and I’m with you.
Usualy use ACF Pro in Themes for completly new projects. In these cases, I handle it the same way like you: ACF Pro is a requirement for the theme to run. But in these cases I’m in complete control of the installed plugins.
I’m going an other route with the current Plugin and use the build in functions of WP or a framework for the options.
I don’t think there is a good answer to this. You could detect that a different version is activated and then deactivate it, but this would not work of the other version was also installed in a plugin, or in the theme. Even if this would work there is still the problem of the two versions not being completely compatible. This is one of the main reasons that I do not build ACF into the plugins that I create that require ACF and instead say that ACF Pro is a requirement of using my plugin. Some of my plugins cannot even be activated if ACF Pro is not active. There have been cases where I had to completely rework a plugin for sites that use themes that include ACF4 because there wasn’t any way to deactivate the requirement for ACF4. There have also been cases where I have refused a project because it was impossible to make the site compatible with my needs.
Sorry for the long non-answer answer.
A cronjob based approach would be the best way, store the values in variables and change the variable with code executed by a cronjob, I found a quite extensive thread on Stackoverflow
To summarise it I quote one of the Threads in case it gets closed
[shortened quote] The script will only run if you have a cron-job or someone access the page. (and a cron job is basically the computer accessing the page at a specific time!)
If you want a variable dependant on time of day simply use a if statement
(pseudo code)
if(now() < $time){ $var = 1; }else{ $var = 2; }
This means that anyone who visits the page before $time gets $var1 and after gets $var2
You will also find an introduction to cronjobs here
The big question is if you are familiar with cron jobs and if your hosting environment allows them.
I hope this will put you on the right track!
Cheers
Johannes
Yes, that’s the cleanest method. And I’ll do this on this praticular installation.
But sometimes I have no control over the used plugins (e.g. if I do work for an Agency). And in these cases it is required by ACF, that I use it as an include in my plugin.
This has to do with the order that the plugins are loaded by WP. The first one loaded wins. There are other significant differences in these plugins work, they really are not compatible. I’ve run into issue with themes that load ACF4 and require it to be installed and active. What you really need to do is install ACF Pro and go through the update procedure and then deactivate ACF4 and never use it again.
This absolutely works for me. Thanks.
Amazing that it’s been so long.
I may look for a plugin dedicated to customising placement of all post metaboxes actually.
Update: I subsequently needed to remove the code from functions.php if I wanted to also respect that custom order with which I had dragged other boxes around. The code keeps resetting them, too, not just the ACF field group.
Catastrophic, all our builds are failing
Forbidden
You don\’t have permission to access /index.php on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.29 (Unix) mod_hive/6.6 OpenSSL/1.0.1e-fips mod_fastcgi/2.4.6 Server at connect.advancedcustomfields.com Port 443
Do you also use Spiderfier and Clusterer?
The fitBounds function still doesn’t seem to work and centers my map somewhere along the equator, so I believe it’s the same in your case?
I will probably find a way with a different map script, like Leaflet or Open Street Map, because Google Maps doesn’t seem to recognize this issue and cannot recreate it (I asked for support there too).
Let me know, if you find a different solution 😉
Okay, I would suggest the following change :
line 136, file /core/fields/select.php
$selected = in_array(strval($key), array_map("strval", $field['value']) ) ? 'selected="selected"' : '';
in order to solve this problem
You can also try
$queried_object = get_queried_object();
$terms = get_field('ti_tag_test', $queried_object->ID);
I’m pretty sure that the issue is that you need to supply the post ID. I think this is a question for the other plugin, how to get and show the current post ID where the sortcode is inserted.
As far as the coffee, I appreciate the offer, but I’m good, thanks anyway.
Then I think it’s the missing post ID.
The query filter/function is located in my child theme’s functions.php.
The code snippet is inserted directly into the post via shortcode by a plugin that enables php code through a shortcode. It’s not in a template file.
You are missing the quotes from the example
// this
'value' => $lagenhet->ID, // matches exactly "123", not just 123. This prevents a match for "1234"
// should be
'value' => '"'.$lagenhet->ID.'"', // matches exactly "123", not just 123. This prevents a match for "1234"
This is just one observation.
If the values stored for an options pages should always be loaded then the options page auto load setting should be set to true. Doing this will reduce the number of queries done since WP loads all of these values in a single query, stores them in a cache for the page and then should not query the DB again for these values.
I created for you a simple class which should do exactly what i said.
In fact, with 1 query per page now i have all my data ready for a better frontend performance.
You can find the Gist here: https://gist.github.com/teolaz/dc595d5beed29ddad18066d01c237464
Ok, so I’ve used the code in in the tutorial: https://www.advancedcustomfields.com/resources/querying-relationship-fields/#single-location.php and modified it a bit to make it more like I want it:
<?php $lagenheter = get_field('lagenheter'); ?>
<?php if( $lagenheter ): ?>
<h4 class="space">Lägenheter med denna planlösning:</h4>
<div class="img-overlay-wrap halfsized">
<img src="<?php echo get_template_directory_uri(); ?>/img/vaningar_both.svg" />
<svg class="flats" viewBox="0 0 200 200">
<?php foreach( $lagenheter as $lagenhet ): ?>
<?php setup_postdata($lagenhet); ?>
<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$planlosning = get_posts(array(
'post_type' => 'lagenhetstyp',
'meta_query' => array(
array(
'key' => 'lagenheter', // name of custom field
'value' => $lagenhet->ID, // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE',
'posts_per_page' => 1
)
)
));
?>
this doesn’t work. Why is that? Could someone please help me? 🙂
I’ve used the following workaround (in this specific example I was forming it for use echoed as inline CSS):
– 2 fields, one the colour picker and the other for a number for opacity (0 to 1 in 0.1 increments)
– In PHP convert the hex colour value to an RGB and then tack the opacity value on the end, like so:
list($r, $g, $b) = sscanf($colour_field_value, "#%02x%02x%02x");
$rgba_colour = 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $opacity_field_value .')';
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.