Display custom post type in author archive thanks to elementor - archive

I'm using Elementor Pro and its "Hello Theme" to build my website. I registered a CPT "movie" in fucntions.php.
Now, I would like to display the archive from this new CPT on my author page but that doesn't seem to work : Elementor says it doesn't find any archive.
I tried adding this piece of code :
add_action( 'pre_get_posts', 'post_types_author_archives' );
function post_types_author_archives( $query ) {
if ( $query->is_author ) {
$query->set( 'post_type', array( 'post', 'movie' ) );
remove_action( 'pre_get_posts', 'post_types_author_archives' );
}`
Unfortunately, it didn't work neither...

Related

Adding post format support to an elementor site but the dropdown shows only 'standard'

I'm trying to add post format support to a site using hello theme for Elementor using the following snippet:
array(
'aside',
'gallery',
'link',
'image',
'quote',
'status',
'video',
'audio',
'chat'
)
);
add_post_type_support( 'post', 'post-formats' );
add_post_type_support( 'page', 'post-formats' );
I've tested it on another site built with Oxygen builder and it works fine, but on this site the options don't show in the dropdown (only Standard shows)
I've seen this question - Wordpress Post Format Dropdown Empty
But I do have an index.php file, so that isn't the problem here
Any ideas I could try?

How can i remove pages generated from image attachments on wordpress?

Image attachment pages show up in search results on website. I need to know how i can remove ones that are currently there. If i can only do this in my database, how can i make sure i delete the actual attachment pages and not the original pages themselves.
here is where the problem is
You can disable the media attachment page on Yoast SEO if you have installed it. Or you can paste this to your functions.php
function myprefix_redirect_attachment_page() {
if ( is_attachment() ) {
global $post;
if ( $post && $post->post_parent ) {
wp_redirect( esc_url( get_permalink( $post->post_parent ) ), 301 );
exit;
} else {
wp_redirect( esc_url( home_url( '/' ) ), 301 );
exit;
}
}
}
add_action( 'template_redirect', 'myprefix_redirect_attachment_page' );
You can use this small snippet - add it to the functions.php of your child theme :
function remove_attachments_from_search() {
global $wp_post_types;
$wp_post_types['attachment']->exclude_from_search = true;
}
add_action('init', 'remove_attachments_from_search');
This will exclude attachment post type from search results.
Hope this helps

How to use Auth component of Cakephp 3 in Event

I'm using CakePHP 3.2 and proffer plugin for image uploading.
I want to rewrite the default path of proffer plugin to upload image and change image name before save.
As per the documentation of proffer from github. I have created an event in /src/Event
Now I want to rename the file like
$this->Auth->user('id').'-'.$row('id').date('dmyhis').ext
this is what I have done
$newFilename = $this->Auth->user('id').'-'.$event->subject()->get('id') . '_' . Inflector::slug($event->subject()->get('name')) . date('ymdhis') . $ext;
But this is giving error that Auth can not be used here. Is there any way to use Auth Component outside controller ?
You can access the logged in user id by loading the session.
use Cake\Network\Session;
$session = new Session();
$userData = $session->read('Auth.User.id');
Use this as a reference: Reading & Writing Session Data
With cake 3.x and after, you should using this:
$this->request->session()->read('Auth');
When debug it
debug( $this->request->session()->read('Auth') );
[
'id' => (int) 2,
'username' => 'admin',
'nice_name' => 'Tommy Do',
'first_name' => 'Huy',
'last_name' => 'Đỗ',
...//and more info in UserTable
]
And access to each element.
$this->request->session()->read('Auth.nice_name');
Print:
Tommy Do
Hope it will help you :D

Cakephp MeioUpload removeOrginal

removeOriginal Dont work on MeioUpload !
i have this code in my post model :
/model/post.php
public $actsAs = array(
'MeioUpload.MeioUpload' => array(
'avatar' =>array(
'thumbnails' => true ,
'thumbsizes' => array('small' => array('width'=>100, 'height'=>100)),
'thumbnailQuality' => 75,
'thumbnailDir' => 'thumb',
'removeOriginal' => true
)
)
);
i want to upload thumbs only , I do not need the source picture .
(cakephp 2.1.2)
thanks
This Behaviour is depreciated and no longer supported (https://github.com/jrbasso/MeioUpload) but I had the same problem and have no need to migrate yet.
For anyone in the same boat as me, you can fix it as follows:
Open Model/Behavior/MeioUploadBehavior.php
Look for this block of code which appears TWICE:
// If the file is an image, try to make the thumbnails
if ((count($options['thumbsizes']) > 0) && count($options['allowedExt']) > 0 && in_array($data[$model->alias][$fieldName]['type'], $this->_imageTypes)) {
$this->_createThumbnails($model, $data, $fieldName, $saveAs, $ext, $options);
}
After the SECOND occurrence insert the following code (which does appear already under the first occurence):
if ($options['removeOriginal']) {
$this->_removeOriginal($saveAs);
}
I did this in my project and seems to be working just fine so far!

CakePHP: Fields not populating in Edit screen

Simple question from an absolute n00b.
I'm trying to create an edit content screen based on the code given in the Blog Tutorial on the Cake site.
Here's my edit function in the controller (it's named Contents):
function edit( $id = null ) {
$this->Content->id = $id;
Debugger::dump( $this->Content->id );
if( empty( $this->data ) ) {
$this->data = $this->Content->read();
Debugger::dump( $this->Content );
}
else {
if( $this->Content->save( $this->data ) ) {
$this->Session->setFlash( 'Content has been updated.' );
$this->redirect( array('action' => 'index') );
}
}
}
And this is edit.ctp:
echo $form->create( 'Content', array('action' => 'edit') );
echo $form->input( 'id', array('type' => 'hidden') );
echo $form->input( 'title' );
echo $form->input( 'nicename' );
echo $form->end( 'Save' );
However, when I visit the Edit screen, the input fields are NOT GETTING POPULATED with the requested data.
I'm using HTML Helper to generate the links and my edit link takes the form of:
http://localhost/contents/edit/id:4c8efaa0-02fc-46bf-ac65-06a07614f57d
As you can see, I've introduced two Debugger dumps in the controller's edit function... those are showing that $this->Content->id remains NULL when I visit this url.
BUT, if I modify the URL to this form (notice that I've used '=' instead of a ':'):
http://localhost/contents/edit/id=4c8efaa0-02fc-46bf-ac65-06a07614f57d
Debugger reports $this->Content->id to have the correct value...
However, my fields still don't get populated.
The index function is working fine though...
function index() {
$this->set( 'contents', $this->Content->find( 'all' ) );
}
The above function is listing the contents correctly!
Where am I going wrong? Am I missing out on some essential bit of code in the View ?
Any help will be much appreciated.
Thanks,
m^e
The problem is here:
http://localhost/contents/edit/id:4c8efaa0-02fc-46bf-ac65-06a07614f57d
Basically your url should look like:
http://localhost/contents/edit/4c8efaa0-02fc-46bf-ac65-06a07614f57d
As you may notice the id: is missing from the correct url. The reason: If you pass the id: this is named parameter and it's not assigned to $id in the function.
Your link for the edit form should look like this:
$this->Html->link('Edit', array('controller'=>contents', 'action'=>'edit', $id_variable));

Resources