ACF url field into button - advanced-custom-fields

I have created a custom field for Post type which I want to show up in the loop which I managed to do with the help of Advanced posts of Ultimate add-on for beaver builder. Now I want the link to be embedded in a button so that users may click the button and it open ups the value under url custom field.
Since I do not prefer core php method for greater control over my web content hence want to know if there is anyway around in html, bootstrap or shortcode to do so ?

I'd recommend setting up a Link field, and following the examples from ACF, pass the $link_url into the anchor's href, click here . Source: ACF | Link
Here's the code they recommend using, which is of the same format that I generally use:
<?php
$link = get_field('link');
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
<a class="button" href="<?php echo esc_url($link_url); ?>" target="<?php echo esc_attr($link_target); ?>"><?php echo esc_html($link_title); ?></a>
<?php endif; ?>
If you're using the fields within a Repeater or a Group, use get_sub_field() instead of get_field().

Related

ACF fields in another plugin

I need to add additional images next to post title, in this case decided to use ACF and add fields (image) into another plugin (Event Schedule). After I added fields in ACF I was trying to add some code from ACF documention however it doesnt work..
P.S. Every post will have different images based on their type. You can choose it while you are editing specific post.
In ACF field menu I chose to return format Image Array.
Tried with all return formats: Image Array, Image URL and Image ID. As I understand plugin cant find the variable acf_name and the image source is left blank.
<div class="wcs-class__meta">
<div class="wcs-class__inner-flex">
<h3 class="wcs-class__title" :title="event.title" v-html="event.title"></h3>
// Using this code from official ACF documentation
<?php
$acf_name= get_field('acf_name');
if( !empty($acf_name) ): ?>
<img src="<?php echo $acf_name['url']; ?>" alt="<?php echo $acf_name['alt']; ?>" />
<?php endif; ?>
</div>
</div>
Now nothing happens, no errors, nothing. However, also it doesnt show those images I want.
Files in the plugins folder do not have access to global functions like get_field();. You can overwrite most plugin files in your theme, in which you should have access to global functions. Keep in mind that when the plugin you override gets updated, the file your are overriding will not. This could cause security issues.
The following article talks about the right ways of custmizing plugins: https://iandunn.name/2014/01/10/the-right-way-to-customize-a-wordpress-plugin/

Assign featured image using MySQL

My client has a custom made theme that uses custom fields instead of featured images.
I added some new plugins and I need to start using featured image instead.
So instead of updating every single post, I thought there's a way to do it using MySQL.
I want to create a MySQL query that transfers all the custom fields values to the featured image.
The theme uses 2 custom fields:
For single image posts:
$post->news_image
For Gallery: // it takes the first image of the gallery
<?php if( has_shortcode($pin->post_content, 'gallery' ) ): ?>
<?php $gallery = get_post_gallery_images( $pin ); ?>
<?php $mythumbs = $gallery[0]; ?>
<?php endif ?>
Should I create a new php file with MySQL in it? and what should it contain?

When posting images using my facebook-like system, it shows the same image on every post

I'm creating a status posting system, similar to the one Facebook has to offer. But, I've run into a bit of a pickle with the images. When I post a status with an image, it literally displays the same image on all of the statuses and posting a new image, it doesn't change at all. I attempted to use an if statement in the postimage.php file (below) to check whether there was an image in that row, but it seems to not have worked at all, and now actually broken the entire thing as to where it won't display the image at all anymore, even if I remove the if statement. So, I really have no clue what's going on here if anyone could lend some assistance, would be great.
Code on my page to display image
<div class="postimages">
<?php
$imgsrc="postimage.php?id={$id}";
?>
<img src="<?php echo $imgsrc ?>" />
</div>
Postimage.php
<?php
include('config.php');
session_start();
$idpost = $_SESSION['idpost'];
$sql = "SELECT * FROM posts WHERE id=$idpost";
$result = $db->query($sql);
$row = mysqli_fetch_assoc($result);
header("Content-type: image/jpeg");
echo $row['pictures'];
?>

Custom Skin: How to get Languages into MediaWiki Sidebar?

I have got a Wiki, with multiple languages, and a custom Skin. My Sidebar is 100% custom-made. I want to get the Language box in there. If someone uses this markup:
[[iwcode:Pagename]]
I want the link and corresponding Language name to pop up in there. How do i get it into my HTML code?
Please help me!
Best regards,
Max
Inside your skin class, yuou should have access to the iw links through $this->data['language_urls']. If you want the links in your sidebar, you can just copy the code from the other skins:
echo "<ul>";
foreach ( $this->data['language_urls'] as $key => $langLink ) {
echo $this->makeListItem( $key, $langLink );
}
echo "</ul>";

Wordpress Custom Sidebar

I am updating my portfolio website and require a different sidebar for different ties of pages, i.e. one for work page and one for the blog page, apparently this can be done using Custom Fields in the page or post.
So, I opened up single.php and found the following code
<?php get_sidebar(); ?>
And replaced it with the code below
<?php $sidebar = get_post_meta($post->ID, "sidebar", true);
get_sidebar($sidebar);
?>
To add a custom sidebar, all I need to do now is apparently add the custom field “Sidebar” and include the name of the sidebar file. For example if I insert “page-01”, it will display sidebar-page-01.php as your sidebar.
After multiple times of trying however this 'isn't' the case, can't see anything wrong with what I am doing, any one have any ideas? Any help would be greatly appreciated!
Thanks guys!
You can do this the way you are doing it by doing your own php function and target the page you need with
<?php
if ( is_home() ) :
get_sidebar( 'home' );
elseif ( is_portfolio page1() ) :
get_sidebar( 'portfolio page sidebar' );
else :
get_sidebar();
endif;
?>
add more elseif statements for as many page & sidebar combination you will have
or you can download this plugin and use the code above the same way