You have to pass in the $query
variable to use it in your function; if you don’t, PHP uses null
.
Try:
function elc_cursos_en_el_blog( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'CursoTL' ));
}
}
add_action( 'pre_get_posts', 'elc_cursos_en_el_blog' );
See pre_get_posts
for the hook’s documentation.
Related Posts:
- How do I get the permalink of a custom post type?
- Row actions for custom post types?
- How to set parent-child relationship between differents custom post types
- Handling front-end file uploads, considering safety and ease of use
- Add content in custom post type page after the title and before columns
- get attachments for all posts of particular post type
- post_tag taxonomy with custom post type
- Count posts or custom post types from last 24 hours (or from today)
- title_save_pre on post publish
- How to add a post from a custom post type as the static page?
- Prepend regular Posts with custom slug, without affecting Custom Post Types?
- Group list of posts by taxonomy and allow for pagination
- Displaying Posts Related to Other Posts by a Taxonomy Term?
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- Using Custom Meta Capabilities on Custom Post Type
- Assigning a role to a specific custom post type (and ignoring other post types)
- How can I programmatically save data into custom fields that contain serialized data?
- Row actions not showing? Why?
- Displaying custom post type on front page
- Custom Role can’t trash Custom Post Type
- Remove “Get Shortlink” button in admin of custom post type
- Using custom post type parent as slug
- Settings API with custom post type menu limitation
- current-menu-item class for custom post type parent
- Changing sort order with pre_get_posts using is_post_type_archive doesn’t change category pages
- How To Enable Block Editor (Gutenberg) for Existing Post Type via functions.php
- Possible for Category Base and Custom post Type to share the same slug/permalink?
- how to add extra GET parameters to post to url with add_rewrite_rule?
- CPT: if more than X images are in post, use pagination
- How to use the Display Name as the post title in a custom post type?
- Removing parent slug in hierachial custom post type
- CPT Archive with core Category
- Open Custom Post Type as PDF
- get_posts() with custom post type does not work outside page.php
- CPT + CMB2: data not displaying for only first post in loop
- Remove edit or add facility for custom post type
- Set a maxlength for the title input in a custom post type
- get_post_meta returning no value in custom post type alert email
- How to get categories linked in posts for a specific post type
- How to edit this code to get the categories in achieve page?
- Cross reference custom post types
- Allow user to only access custom post type
- Filtering posts list table
- Template not working for the custom Post type
- How to Create Template File for Parent Page of Custom Post Type
- Which Template Page Should I Use?
- CRUD operations in wordpress
- wp_insert_post wrong post type [closed]
- WordPress Picks Up Wrong Template for Custom Post Type Archive Page
- How to hyperlink content from archive page with custom post-type
- Archive-posttype.php isn’t loaded
- List of all entries of custom-post-type: Add year-parameter?
- Should I use custom taxonomies or not?
- get comments by current user inside page template
- Attaching a Custom Taxonomy to Posts?
- custom post type problem
- Reordering admin columns for CPT with custom taxonomy and an added custom field
- The Difference Between Categories and Tags and Taxonomies and Terms
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- List Custom Post Types in Admin Dashboard
- CPT Archive pre_get_posts not working?
- wp_editor for custom post type doesn’t save value
- Hide text if query has no posts
- Display registerd taxonomy in admin dashboard
- Shortcode / WP_Query in post changes context
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Am I mixing up the concept of posts pages and categories?
- How to achieve a multi-taxomony layout with posts?
- Displaying all posts by category and showing content on click
- Custom post type and custom taxonomy key lenght & query performance
- Feature image Gallery made from Custom Post type + Categories
- Custom post type in slider front page Breaking layout
- Getting data from dynamically allocated metaboxes within a custom post
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- check_admin_referer not working in custom meta box for custom post type
- Custom permalink with custom taxonomies for custom post type
- Meta query broken since 4.7.4 Update
- Custom post type , page template not grabbing the page template
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Getting wrong ID
- Remove sequential number from permalinks
- custom post type archive slug vs. custom page template
- Related post without plugin for custom post types
- Show custom taxonomies in admin panel under custom post type
- Custom Post Types in plugins?
- Custom role, capabilities, and post type: preview button wrecks things
- Most efficient way of deleting post
- Problem with menu categories doubling up when updating database?
- Noob Loop Question
- Custom Post Type fields not showing in dashboard
- How to hide home title on pages and posts?
- WP_Query is getting the post but the_post() not rendering any Post
- Display associated taxonomy child name on single CPT page
- Custom Post Type to Plugin
- How to display serial numbers in foreach loop while querying posts?
- Get images only from a certain post type
- Filter page ID outside the loop and order
- the_post_navigation in single page with multiple taxonomies
- display related posts based on the PAGE TITLE
- Custom Post Types Permalink