Ok solution found. I forgot to use the {} and now it works. Here goes:
<?php
$query = new WP_Query( array( 'post_type' => array( 'custom_post_type' ) ) );
$i = 0;
while ( $query->have_posts() ) : $query->the_post();
if ($i%2==0){
echo '1st post here';
}
if ($i%2==1){
echo '2nd post here';
}
$i++;
endwhile;
?>
Related Posts:
- How to display by default only published posts/pages in the admin area?
- Is there an if statement that can determine if a post in the loop is the last post?
- Can I load posts via Ajax?
- Custom colors for post rows based on post meta value
- All WordPress scheduled posts are being published immediately
- WordPress Delete hook with wp_delete_post function?
- Get all posts by post_author
- Linking to page with all posts
- Undelete post (untrash)?
- Delete Post From Front-End and attachment permanently
- Every possible way to get data (posts) from WordPress
- Double count view in archive.php
- disable column on post and user list
- Multiple social buttons with a fast loading? [closed]
- How can I display widget in a Page or Post?
- Different style for most recent article
- How can I replace the text at the top of a custom column into a icon?
- count the total number of comments the user has received for his published posts
- How to Orderby Comments by post title?
- Multiple posts with fixed order position
- Hide a specific category in admin All Posts page (WordPress)
- Force the “Choose from the most used tags” meta box section to always be expanded
- Display Meta Values in Custom Filter – Admin Custom Posts
- Get user categories with most posts in it
- How to display two blog categories as separate sections on one page?
- Retrieve post ID from “querying” URL
- When open add new post or page WordPress add post with ID=0 continuously [closed]
- Thumbnail & Category link aside post
- My wordpress based site is publishing the same post twice
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- How to make a sum of all posts displayed in a loop
- Notification when visitor is on specific WordPress Article
- First x post with another template then the others
- When creating a post how do you select the format?
- Assign published posts to another user automatically
- add bootstrap post slider with tabs
- Show all posts shows a blank white page in WP 4.2.2 [closed]
- Font shows up as Arial instead of Times [closed]
- Fast publishing in wordpress
- Getting Duplicate Posts on Home Page with Widget Added Between Posts
- Add Blog to WP homepage Manually
- Shortcode with ‘year’ parameter
- Get URL from all images in a post
- Change the default blog post post attribute template name from “default template” to something else
- Getting property of non-object when looping through post objects from ACF
- How to get the ability to change the author of a post
- Defined function isn’t showed on page
- single post showing blank page in custom template
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Get total post from an author
- How to embed the content of one post into another site
- Prohibit saving a post without providing a title
- Limiting post list by taxonomy
- select post preview image from nextgen gallery
- How to add tag(s) to all posts from a specific category? [duplicate]
- Auto post Spams on my wordpress blog?
- Standalone form does not post to the url when form fields are populated (otherwise it does)
- Will multiple category descriptions effect my search engine optimization?
- How to prevent to create same url of post, if the previous was deleted?
- How to select a category automatically based on a word in WordPress post title?
- Open posts in popup window
- How to merge the content of posts that have the same title?
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- ‘QTags.addButton: arg2 distorts the button rather than just shows
- WordPress Post 403 Error Based on Slug
- How to add first 3-4 post tags on WordPress Post Title
- WordPress React re-rendering to many times
- How do I assign an attachment to a post using only the REST API?
- How to add class to specific navbar item when post parent category is in specific category
- How to get unmodified post content?
- Posts are not displaying on their category and tag page
- Random post_id at wp_insert_post
- Sorting post by custom field and category
- WordPress display page information rather than post
- Post Category link is same with Page link
- I need show posts by customer (Shortcode)
- Show custom post category for single post
- How to delete all posts with dead image urls?
- Get a list of categories that are related to posts
- Allow author to duplicate but not edit post
- Best Way to detect unique posts in wp rest api
- ACF Relationship – Get Parent’s Post Object
- Post Per Page For Portfolio
- How to edit label_submit styling?
- How to modify specific parts of a post content in WordPress
- How do I allow my post to update it’s date every week
- How can I show my post under a certain content name?
- How Can I Limit Users to Post Creation For My Frontend Theme?
- How to display only one post on first category page and rest on next pages?
- Show Custom Post From Logged In Author
- How to display a paginated list of posts from one category on a page? [duplicate]
- Is there a way to separate wordpress titles from their posts?
- Viewing category won’t show up Custom post type posts
- Get attachment if matches a variable
- custom sort posts in archive/taxanomy page
- Trying to create shortcode listing custom posts, but formating not being included
- Show some texts in posts belonging to Specific category
- How to automatically convert a form with HTML link into post
- WordPress Post Updating is Not Working