Assign featured image using MySQL - 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?

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/

ACF url field into button

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().

Merge description & additional information tab in woocommerce

I am using woocommerce on my wordpress website and I want to merge the description and additional information tabs on the product pages. I want to place the content of both tabs underneath eachother. Note that there is a similar question (with answer) posted here: Merge Description and additional information tab in Woocommerce
However, this answer places the content of the tabs in two columns instead of underneath eachother. I tried using this answer and tweaking it in order to get the contents to show underneath eachother, but my knowledge of html and css is not sufficient enough to solve this problem (I am new to coding, and even though I am proud to say that I managed to do some edits and minor fixes, this problem is definitely out of my league...)
Is there anyone who could help me out?
Thanks in advance! :)
I found out a simple way to do this. (review would be great!) The content shown in description and additional information tabs is extracted from the database and displayed in these files:
theme/woocommerce/single-product/description.php
theme/woocommerce/single-product/additional-information.php
By copying the following code of additional-information.php to description.php the content of the two are merged into one tab.
global $product;
$heading = esc_html( apply_filters(
'woocommerce_product_additional_information_heading', __( 'Specification',
'rehub_framework' ) ) );
?>
<?php if ( $heading ) : ?>
<div class="rh-woo-section-title"><h2 class="mt0"><?php echo ''.$heading; ?
>: <span class="rh-woo-section-sub"><?php the_title();?></span></h2></div>
<?php endif; ?>
<?php do_action( 'woocommerce_product_additional_information', $product ); ?>

Yii2 Create & use variable with views folder scope

I am trying to create a Yii2 theme, & would like to set a variable that with scope of the entire views folder. For a single page theme I used...
$assetDir = Yii::$app->assetManager->getPublishedUrl(
'#vendor/path/to/assets/folder'
);
in index.php & I then I accessed it using...
<img src="<?= $assetDir ?>/img/image.jpg" alt="">
For partials I am able to pass that using...
<?= $this->render('_partial.php', ['assetDir' => $assetDir]) ?>
I am now wanting to do similar in a theme with multiple pages & cannot find how to do that without setting $assetDir in each page. I imagine it would be set in the main.php layout.
Use params array for this as stated in Sharing Data among Views.
The view component provides the params property that you can use to share data among views.
For example, in an about view, you can have the following code which specifies the current segment of the breadcrumbs.
$this->params['breadcrumbs'][] = 'About Us';
Then, in the layout file, which is also a view, you can display the breadcrumbs using the data passed along params:
<?= yii\widgets\Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

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