Yep, thats another way to do it, just have to keep your naming convention consistent.
Hi Lazlo
This code should help you out if you are returning an image url
<img src="<?php the_field("image"); ?>" alt="">
Replace image with the field name that the image is stored in.
If you want to get a specific image image then set the following options.
Return an “image object” to the front end when the field is called
The image object option will return different properties and image sizes for the image uploaded. The image sizes can be accessed using the following
<?php
$image = get_field("image");
$image = $image["sizes"]["image_size"];
?>
<img src="<?php echo $image; ?>" alt="">
Replace “image_size” with the image size name that you would like to show. If you do not know the name of the image sizes, use the following and then take the name from it.
<?php
$image = get_field(“image”);
print_r($image[“sizes”]);
?>
The error appears when a page is trying to redirect to another but there has already been content outputted to the current page, for example:
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
The “html” tag has already been output so the page will error when trying to redirect. Check if this is happening at all in your code
The easiest way to achieve this would be to have an if statement in code that retrieves the image from a url based on the selected option. ie:
<?php
$image_url = "";
$option = get_field("selected_option");
if($option=="option1"){
$image_url = "image1.jpg";
}else if($option=="option2"){
$image_url = "image2.jpg";
}
?>
<img src="<?php echo $image_url; ?>" alt="Image">
Hi Orimomo
A custom query using the get_posts function is your best option, http://codex.wordpress.org/Template_Tags/get_posts
The custom query could be build using the following
<?php
$args = array(
'posts_per_page' => -1,
'offset' => 0,
'category' => '',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => 'player_goals',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args );
?>
You could then use a loop to iterate over all of the returned post items and use standard functions to get the data
foreach ( $posts_array as $post ) : setup_postdata( $post ); ?>
<?php
$name = get_field('player_name);
$goals = get_field('player_goals);
?>
<?php endforeach;
If you have created a custom post type for players change the post_type from post to whatever you have called your custom post type
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.